Wednesday, October 30, 2013

uses a non-entity as target entity in the relationship

This error or similar appears in the Glassfish server log even though everything appears correct in the project.  Double-check the persistence.xml to be sure it is correct.  If it is, the problem is likely being caused by a cached persistence.xml.  If you are using an IDE such as Netbeans be sure to Clean & Build before deploying.

Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.

According to this site (site), this is caused by a Glassfish bug and redeploying will fix this.  The following steps solved the issue:

  1. Undeploy the project
  2. Restart the Glassfish server
  3. Clean and build project
  4. Deploy project to Glassfish server

These steps work using the following configurations:
  • Netbeans 7.4 and Glassfish 4.0
  • Netbeans 8.0 and Glassfish 4.0

Friday, October 25, 2013

SSH issues in Ubuntu

Problem 1:

When using ssh to connect to a remote server from an Ubuntu based machine, there is a long delay before the password prompt is displayed.


On the local machine, edit the ~/.ssh/config file (or create it if it does not exist) and add the line:


Problem 2:

When connected to a remote server with ssh, if idle too long, connection will be ended with this message:

Write failed:  Broken pipe


On the local machine, edit the ~/.ssh/config file (or create it if it does not exist) and add the line:

ServerAliveInterval 120

Monday, October 14, 2013

Runtime ClassNotFoundExceptions may result


When using Eclipse Kepler to create Java EE projects, I was getting the following warnings:

Classpath entry <jar library here> will not be exported or published.  Runtime ClassNotFoundExceptions may result.


The warning is telling me that the jar file (in my case it was a log4j library) will not be included in the archive that is deployed to application server.  This warning is just a reminder that unless you put the jar file in the classpath of the application server you will receive ClassNotFoundExceptions when trying to run the projects.  A very handy reminder but somewhat irritating since I don't like the little yellow triangle with exclamation point that appears on the project because of the warning.  The can be fixed by adding the jar file for the required library to the Deployment Assembley (Project Properties -> Deployment Assembly -> Add... -> Java Build Path Entries -> <jar library>).  The downside to this is that the jar will be included in the EAR or WAR that is generated thus making is much larger.

Wednesday, October 2, 2013

Null or zero primary key encountered in unit of work clone

Null or zero primary key encountered in unit of work clone [Object@3622086c], primary key [0]. Set descriptors IdValidation or the "" property.

Ran into this at runtime when running a EJB on Glassfish using JPA Entities.  The problem turned out to be a missing annotation on one of the properties in one of the JPA Entities (@GeneratedValue).

The value in question was the primary key for the table and was auto-generated.

Full corrected code:
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;