28 September 2011

GlassFish 3 server - Enabling JPA for WAR module

My first sample web application in GlassFish 3 server involving JPA 2.0 and GlassFish was spitting out the error "Unable to retrieve EntityManagerFactory for unitName XXX". Other settings were right.
Solution: Edit domain.xml to enable JPA as below. By default JPA is enabled for EJB modules.

<module name="yourwebmodulename">
<engine sniffer="jpa"></engine>

How to have WAR and JAR folders exploded in an EAR project built by Maven

Add the attribute unpack=true (example below)

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>com.urcompany</groupId>
<artifactId>xxx-web</artifactId>
<contextRoot>/</contextRoot>
<unpack>true</unpack>
</webModule>
<ejbModule>
<groupId>com.urcompany</groupId>
<artifactId>xxx-ejb</artifactId>
<unpack>true</unpack>
</ejbModule>
</modules>
</configuration>
</plugin>

05 June 2011

How to debug the root cause for AssertionFailure: null id in entry (don't flush the Session after an exception occurs)

To figure out the real (root) cause of the error, please use the following snippet

     ClassValidator cv = new ClassValidator(YourEntity.class);
                    InvalidValue[] validationMessages = cv.getInvalidValues(yourInstanceOfEntity);
                    if (validationMessages.length > 0) {
                        for (InvalidValue iv : validationMessages) {
                            System.out.println("Invalid value::" +iv.getMessage()+"::"+iv.getPropertyName()+"::"+iv.getValue());
                        }
                    }