[help] hibernate inheritance mapping and tomcat

8 posts / 0 new
Last post
atao
Offline
Joined: 10/15/2008
[help] hibernate inheritance mapping and tomcat

Vincent,

I have 3 classes:

- org.popsuite.common.model.AccountingEntry

- a derived one, org.popsuite.hr.model.Contribution

- and org.popsuite.hr.model.Paylsip with a attribut "contributions" (composition)

Hibernate doesn't create any mapping file for Contribution but there is an expected "joined-subclass" in AccountingEntry.hbm.xml:

    <joined-subclass
      name="org.popsuite.hr.model.Contribution"
      dynamic-insert="true"
      persister="org.jspresso.framework.model.persistence.hibernate.entity.persister.EntityProxyJoinedSubclassEntityPersister"
      dynamic-update="true"
      table="CONTRIBUTION">
      <key column="ID"/>
      <many-to-one cascade="none" name="rubric">
        <column name="RUBRIC_ID"/>
      </many-to-one>
      <many-to-one cascade="persist,merge,save-update" name="payslip">
        <column name="PAYSLIP_ID" not-null="true"/>
      </many-to-one>
    </joined-subclass>

When I try to start Tomcat with this application, I get the exception below.

Any idea?

Regards

Pierre

 

INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
10 déc. 2009 12:28:21 org.apache.catalina.core.StandardContext listenerStart
GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.popsuite.hr.webapp.TestDataContextListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in class path resource [org/jspresso/framework/application/backend/persistence/hibernate/commons-hibernate.xml]: Cannot resolve reference to bean 'hibernateSessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [org/popsuite/hr/config.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: org.popsuite.hr.model.Contribution
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
    at org.jspresso.framework.application.startup.development.AbstractTestDataPersister.<init>(AbstractTestDataPersister.java:52)
    at org.popsuite.hr.development.TestDataPersister.<init>(TestDataPersister.java:32)
    at org.popsuite.hr.webapp.TestDataContextListener.persistTestData(TestDataContextListener.java:18)
    at org.jspresso.framework.application.startup.development.AbstractTestDataContextListener.contextInitialized(AbstractTestDataContextListener.java:54)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [org/popsuite/hr/config.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: org.popsuite.hr.model.Contribution
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    ... 30 more
Caused by: org.hibernate.MappingException: Association references unmapped class: org.popsuite.hr.model.Contribution
    at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2399)
    at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2678)
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1177)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1162)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
    ... 40 more
10 déc. 2009 12:28:21 org.apache.catalina.core.StandardContext start

 

vvandens
Offline
Joined: 05/29/2008
[help] hibernate inheritance mapping

Hi Pierre,

Have a look at ${project}/core/pom.xml in the generator section. If you use different packages for the Hibernate persistent classes, you have to tweak the "-includePackages" argument (comma separated). If you want to exclude certain classes from the included packages, you can play with "-excludePatterns" (comma separated) which exclude classes if their fuly qualified name match the patterns listed.

If it's just a mapping generation probem, you might have to play with the "<includes>" and "<exclude>" of the xdoclet section in the same pom. By default, only classes containing a model (<includes>**/model/**/*.java</includes>) package are parsed.

 

HTH,

Vincent

atao
Offline
Joined: 10/15/2008
[help] hibernate inheritance mapping

Vincent,

you have to tweak the "-includePackages"

Already done:

                  <arg value="org.popsuite.common.model,org.popsuite.hr.model" />

 

By default, only classes containing a model (<includes>**/model/**/*.java</includes>)

All the classes are either in org.popsuite.common.model or in org.popsuite.hr.model packages.

So I'm still stuck.

It seems that Hibernate is expecting for Contribution something else that the "joined-subclass" in AccountingEntry.hbm.xml.

Regards

Pierre

 

 

atao
Offline
Joined: 10/15/2008
[help] hibernate inheritance mapping

And I also changed hibernateSessionFactory in core/src/main/resources/org.popsuite.hr.config.xml, to add in "mappingLocations":

        <value>classpath*:org/popsuite/common/**/*.hbm.xml</value>

 

atao
Offline
Joined: 10/15/2008
[help] hibernate inheritance mapping

Vincent

I tried to extract the joined-subclass from AccountingEntry.hbm.xml and put it in a new file Contribution.hbm.xml (under core/target/classes) with an extends attribute:

<hibernate-mapping
  default-access="org.jspresso.framework.model.persistence.hibernate.property.EntityPropertyAccessor">
    <joined-subclass
      name="org.popsuite.hr.model.Contribution"
      dynamic-insert="true"
      persister="org.jspresso.framework.model.persistence.hibernate.entity.persister.EntityProxyJoinedSubclassEntityPersister"
      dynamic-update="true"
      extends="org.popsuite.common.model.AccountingEntry"
      table="CONTRIBUTION">
      <key column="ID"/>
      <many-to-one cascade="none" name="rubric">
        <column name="RUBRIC_ID"/>
      </many-to-one>
      <many-to-one cascade="persist,merge,save-update" name="payslip">
        <column name="PAYSLIP_ID" not-null="true"/>
      </many-to-one>
    </joined-subclass>
</hibernate-mapping>

OK, now hibernate found this new file, but I get:

Caused by: org.hibernate.MappingException: Following superclasses referenced in extends not found: org.popsuite.common.model.AccountingEntry

This classe is present under core/target/classes...

So, still stuck.

Regards

Pierre

 

 

 

 

 

vvandens
Offline
Joined: 05/29/2008
[help] hibernate inheritance mapping

Pierre,

Don't have much ideas... Unless a class loader issue.

Although I'm sure you've already tried it : mvn clean. I've seen weird things when there were generated files wandering around from previous generations and the model has changed in between.

What about in swing ? It may be easier to track the problem.

Just for trying, if it doesn't require too many changes, what if you put AccountingEntry in the same packages as the other 2 entities (btw, all 3 classes are actually defined as "Entities", right) ?

All classes and hbm files are packaged in the same jar ? No package split between different jars ?

 

I'm sorry I can't help you more, but I've never experienced such a behaviour...

 

Regards,

Vincent

vvandens
Offline
Joined: 05/29/2008
I think I get it...

Forget my yesterday night post.

Your problem comes very probably from the fact that the application actually defines 2 config.xml :

  • 1 for the 2-tier swing application (the one you changed in core/src/main/resources/[app package]). This one is packaged in the core jar.
  • 1 for the 3-tier version (that resides in webapp/src/main/resources/[app package]). This one is in the webapp WEB-INF/classes.

Using the classloading mecanism, when your application runs as a WAR in an app server, it uses the config.xml from the webapp module whereas when it runs as swing, it uses the one from the core module.

The idea behind this config.xml duplication is to be able to keep a single build for 2-tier (app server less) and 3-tier versions of the application while still being able to configure things independently. It allows, for instance, to leverage the application server capabilities (use JNDI to lookup the datasource backing the Hibernate session, configure the Spring transaction template to use tha application server transaction manager, ...) while keeping a "simpler", J2EE-less, config for 2-tier swing.

So the update you made to hibernateSessionFactory to load the extra hbm.xml from other packages must also be done in the webapp config.xml.

 

I hope this is a little clearer, now. Tell me if it fixes your problem.

 

Best,

Vincent

atao
Offline
Joined: 10/15/2008
[help] hibernate inheritance mapping

Vincent,

Just to tell you I did what you suggested for the webapp config.xml. I just try again wings/qooxdoo/flex versions: Hibernate and Tomcat seem happy. No more such exception.

Thanks

Pierre