Tuesday, March 26, 2013

An annotation processor threw an uncaught exception.

When compiling a EJB project there might be a case in which the java EE API comes before eclipseLink API in the class path. Hence the following error may be generated.

An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/PersistenceException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
.....
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
../..//nbproject/build-impl.xml:839: The following error occurred while executing this line:
../../nbproject/build-impl.xml:258: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 1 second)

The solution is simple:-) Just make the eclipseLink API first in the project libraries configuration. 

Monday, March 25, 2013

javax.naming.NameNotFoundException: org.mk.rc.intf.StaffsBeanRemote

When calling an EJB, I got an error like the following....

com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=org.mk.rc.client.Client/staffsBean,Remote 3.x interface =org.mk.rc.intf.StaffsBeanRemote,ejb-link=null,lookup=,mappedName=,jndi-name=org.mk.rc.intf.StaffsBeanRemote,refType=Session into class org.mk.rc.client.Client: Lookup failed for 'java:comp/env/org.mk.rc.client.Client/staffsBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl}
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:703)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:470)
....

Caused by: javax.naming.NameNotFoundException: org.mk.rc.intf.StaffsBeanRemote#org.mk.rc.intf.StaffsBeanRemote not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
..... 

The problem is, I didn't add StaffsBeanRemote bean name to application-client.xml file. Just add as follow and works fine. 

<ejb-ref>
    <ejb-ref-name>StaffsBean</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <remote>org.mk.rc.intf.StaffsBeanRemote</remote>
 </ejb-ref>

Enjoy :-)


Saturday, March 23, 2013

The module has not been deployed.

When I tried to use Hibernate (JPA 2.0) as a persistence provider in glasfish 3.x application server , I encountered the following problem and my EJB application can't be deployed.


Initializing...
deploy?DEFAULT=/home/alemnew/NetBeansProjects/LMS-ejb/build/classes&name=LMS-ejb&libraries=/home/alemnew/NetBeansProjects/LMSRemote/dist/LMSRemote.jar,/home/alemnew/NetBeansProjects/LMS-ejb/lib/ejb3-persistence.jar,/home/alemnew/NetBeansProjects/LMS-ejb/lib/hibernate-annotations.jar,/home/alemnew/NetBeansProjects/LMS-ejb/lib/hibernate-commons-annotations.jar,/home/alemnew/NetBeansProjects/LMS-ejb/lib/hibernate-validator.jar,/home/alemnew/NetBeansProjects/LMS-ejb/lib/hibernate3.jar,/home/alemnew/NetBeansProjects/LMS-ejb/lib/hsqldb.jar&force=true failed on GlassFish Server 3.1.2 
 Error occurred during deployment: Exception while preparing the app : java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence. Please see server.log for more details.
/home/alemnew/NetBeansProjects/LMS-ejb/nbproject/build-impl.xml:971: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 1 second)
=========================================

As a temporary solution I used eclipseLink (JPA 2.0) instead.  The problem seams like, glassfish doesn't have Hibernate as a persistence provider by default. Hence, manual operation is needed, I think. I will try to solve......