-->
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.  [ 2 posts ] 
Author Message
 Post subject: Can't find annotations in a seporate jar???
PostPosted: Wed Dec 30, 2009 7:21 pm 
Newbie

Joined: Fri May 23, 2008 11:12 am
Posts: 8
I have hibernate partially working but now I ran into a really bizzare issue. Essentially the system is auto-detecting hibernate annotated classes but only classes that are in the same jar as the persistence xml file.

I have two jar files in my web app, each has a foo-persistence.xml file in the /META-INF folder of the jar (named differently in each jar so there's no name conflicts). Also in each of these jar files is a different set of entities. The persistence xml is identical for each. Whichever persistence xml file I use, it will find the annotated hibernate classes in the jar where the persistence xml file lives, but it won't find the annotated entities in the other jar file.

Any ideas???

The persistence xml files are identical and look like this...

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
  <persistence-unit name="companyName">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
  </persistence-unit>
</persistence>


In my spring config, I have the entity manager configured as follows...

Code:
<bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:/META-INF/${spring.project.build.finalName}-persistence.xml"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true"/>
                <property name="generateDdl" value="false"/>
                <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>
            </bean>
        </property>
    </bean>


Last edited by otatop on Thu Dec 31, 2009 7:02 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Can't find annotations in a seporate jar???
PostPosted: Thu Dec 31, 2009 7:02 pm 
Newbie

Joined: Fri May 23, 2008 11:12 am
Posts: 8
so I solved the issue and will post it to be nice.

Apparently jars do matter when scanning. Create a new persistence.xml as follows and put it in WEB-INF/classes/META-INF/persistence.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="companyName">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jar-file>/WEB-INF/lib/foo.jar</jar-file>
        <jar-file>/WEB-INF/lib/bar.jar</jar-file>
    </persistence-unit>
</persistence>


Then I modified my spring config to
Code:
    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:/META-INF/persistence.xml"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true"/>
                <property name="generateDdl" value="false"/>
                <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect"/>
            </bean>
        </property>
    </bean>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.