-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Need help - annotated classes not working in my deployed app
PostPosted: Fri Feb 09, 2007 2:42 pm 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
I'm having an interesting problem show up when I attempt to use my Annotated classes in a deployed web application. Here is the scenario :

<Works>
1 - I deploy my web application (in a .war file). My persistence unit is setup in my persistence.xml file as a JTA datasource. The following two options are also set :
Code:
         <property name="hibernate.archive.autodetection" value="class, hbm" />
         <property name="hibernate.mapping.precedence" value="hbm" />


Once the app is deployed I can access it correctly and everything runs fine.

<Doesn't Work>
2 - I deploy my web application the same way, only I change the persistence.xml file to use the class files instead of the hbm.xml files :

Code:
         
<property name="hibernate.mapping.precedence" value="class" />


Once the app is deployed I attempt to access the first page in the application and I get the following error in my appserver log files :

Code:
2007-02-09 11:16:42,817 DEBUG: AnnotationConfiguration: processing manytoone fk mappings^M
2007-02-09 11:16:42,817 DEBUG: AnnotationConfiguration: Found referenceEntityName = us.co.douglas.soso.model.District^M
2007-02-09 11:16:42,817 DEBUG: AnnotationConfiguration: Found classMapping = null^M
2007-02-09 11:16:42,817 ERROR: PersistenceUtil: Error finding or building entityManagerFactory! Cause: ^M
javax.persistence.PersistenceException: java.lang.NullPointerException^M
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:252)^M
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)^M
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)^M
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)^M
        at us.co.douglas.soso.util.PersistenceUtil.getEntityManagerFactory(PersistenceUtil.java:114)^M
        at us.co.douglas.soso.util.PersistenceUtil.getEntityManager(PersistenceUtil.java:240)^M
        at us.co.douglas.soso.util.PersistenceUtil.getEntityManager(PersistenceUtil.java:222)^M
        at us.co.douglas.soso.filters.HibernateJTAFilter.doFilter(HibernateJTAFilter.java:107)^M
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:210)^M
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)^M
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)^M
        at java.security.AccessController.doPrivileged(Native Method)^M
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)^M
        at us.co.douglas.soso.filters.JurisdictionFilter.doFilter(JurisdictionFilter.java:228)^M
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:210)^M
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)^M
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)^M
        at java.security.AccessController.doPrivileged(Native Method)^M
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)^M
        at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)^M
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:210)^M
        at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:55)^M
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:161)^M
        at java.security.AccessController.doPrivileged(Native Method)^M
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)^M
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)^M
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:225)^M
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)^M
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)^M
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132)^M
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)^M
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933)^M
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:185)^M
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:653)^M
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:534)^M
        at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doTask(ProcessorTask.java:403)^M
        at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:55)^M
Caused by: java.lang.NullPointerException^M
        at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:383)^M
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)^M
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)^M
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)^M
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)^M
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)^M
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)^M
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)^M
        ... 39 more



From looking at the code, it would appear that AnnotationConfiguration.getClassMapping() is returning null for the supplied referenceEntityName.

Has anyone seen this issue before? Is it an error in my annotated file? (They were generated by the Hibernate Eclipse plugin) It's odd that the app runs fine when using the hbm.xml files, but fails when trying to use the annotated files. The annotated files were created based on the hbm.xml files (using the Hibernate Eclipse plugin).

Any help would be greatly appreciated. I can attach my persistence.xml and a couple of my annotated classes if needed.


Hibernate version: 3.2.2

Hibernate EntityManager version: 3.2.1-GA

Hibernate Annotations version: 3.2.1-GA

App Server SunOne8


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 3:47 pm 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
BTW, the appserver is using version 1.5.0_05-b05 of the JRE.

Could this be what's causing the problem? I'm wondering if this version of the JRE doesn't have the full JPA functionality implemented.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 5:48 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
JPA isn't part of JSE at all.
It's what Hibernate and the associated jars provide for you.
If you didn't have those on your classpath you'd get other errors, like NoClassDefFoundErrors and things like that when the JVM tries to load classes it can't find.


If I were you I'd run the thing in a remote debugger and set some breakpoints in your PersistenceUtil before it hits line 114, which is where something is going wrong that eventually leads to that NPE.

Maybe you've an error in your configuration somewhere, like a missing annotation.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 7:36 pm 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
One other thing, the pattern I'm using in this app is to have POJOs that are abstract, and then have my proxy classes extend the base classes.

Only my abstract classes are annotated, for example :

Code:
@Entity
@Table(name = "STATE")
public abstract class StateBase implements java.io.Serializable {
...
}

public class State extends StateBase {

    // Put any transient methods / variables here   


}


I'm assuming that the annotations get inherited in this pattern. I haven't seen anything in the forums that says one way or another.

Does anyone know if this is valid, or do I have to annotate my concrete class as well as the abstract class?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 10, 2007 2:28 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
hmm, you'd want it the other way around.

Annotate the abstract classes as @MappedSuperClass and the implementing classes as @Entity.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 10, 2007 2:57 pm 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
It seems backwards to me to do that.
(I don't have the code in front of me, so I can't actually try it right now)

If I have a State database table with the following columns :
id
state_name
state_description

and my code looks like this :

Code:
@Entity
@Table(name = "STATE")
public abstract class StateBase implements java.io.Serializable {
    protected String stateName;
    protected String stateDescription;

}

public class State extends StateBase {

    // Put any transient methods / variables here   
    public String getCombinedName() {
        return stateName + " - " + stateDescription;
    }

}


It seems that if I put the @Entity on my State class, then Hibernate will expect me to have a combinedName column in my database, when I only really have the stateName and stateDescription columns.

Is my thought process wrong on this one? And if so, can you explain where I'm off?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.