Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Entity objects in a persistence archive file (.par)
PostPosted: Thu Sep 15, 2005 3:33 pm 
Newbie

Joined: Thu Sep 15, 2005 2:48 pm
Posts: 4
Hibernate version: 3.1 beta3
EntityManager version: 3.1 beta3

Section 2.2 of the entity manager docs suggests that all classes in a persistence archive that are marked with @Entity will be added to the persistence unit configuration. I have bundled my @Entity objects along with META-INF/persistence.xml into a persistence archive file (.par) and put that archive on my classpath. My persistence.xml looks something like this...

Code:
<entity-manager>
    <name>mymanager</name>
    <properties>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost/mydb"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.password" value="secret"/>
        <property name="hibernate.connection.username" value="me"/>
    </properties>
</entity-manager>



I have found that if I don't have class elements in my persistence.xml file then when I try to persist an object I get an exception like this...

Code:
     [java] java.lang.IllegalArgumentException: Unknown entity: com.foo.Bar
     [java]     at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:133)


The archive does contain my persistent classes that have been marked with @Entity. If I had a class element to my persistence.xml like this things seem to work fine...

Code:
<entity-manager>
    <name>mymanager</name>
    <class>com.foo.Bar</class>
    <properties>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost/mydb"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.password" value="secret"/>
        <property name="hibernate.connection.username" value="me"/>
    </properties>
</entity-manager>


I have read Chapter 6 of the current draft of the JSR220 spec. and it still is not clear to me how this is supposed to work in a J2SE environment.

Do the classes need to be specified in class elements in my persistence.xml file or should the environment find that they are in the persistent archive and have been marked with @Entity? I am specifically interested in the behavior in a J2SE environment, not in a J2EE container.

Thanks for your time.



Jeff

_________________
Jeff Brown
brown_j@ociweb.com
Principal Software Engineer
Object Computing Inc.
http://www.ociweb.com/

Autism Strikes 1 in 250
Find The Cause ~ Find The Cure
http://www.jeffandbetsy.net/walkfar2005/
http://www.naar.org/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 3:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7179
Location: Atlanta, USA
I do have some unittests that test this case, how did you package your par exactly?

_________________
Emmanuel
Check Hibernate Search in Action out


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 3:52 pm 
Newbie

Joined: Thu Sep 15, 2005 2:48 pm
Posts: 4
The archive structure looks like this...

Code:
META-INF/
META-INF/MANIFEST.MF
com/
com/foo/
com/foo/Bar.class
META-INF/persistence.xml


Can you point me to the unit tests that you referred to? That might help me figure it out.

Thanks again!



jb

_________________
Jeff Brown
brown_j@ociweb.com
Principal Software Engineer
Object Computing Inc.
http://www.ociweb.com/

Autism Strikes 1 in 250
Find The Cause ~ Find The Cure
http://www.jeffandbetsy.net/walkfar2005/
http://www.naar.org/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 4:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7179
Location: Atlanta, USA
PackagedEntityManagerTest, the ant script build several archives and this test uses them.

Try to set the log to debug too

_________________
Emmanuel
Check Hibernate Search in Action out


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 4:29 pm 
Newbie

Joined: Thu Sep 15, 2005 2:48 pm
Posts: 4
Some of the test par files contain the Hibernate specific hbm.xml files. Is that the key? Is it a requirement to either have class elements in the persistence.xml file or have the hbm.xml files in the .par? I am hoping that I can simply include the @Entity objects in the .par and that makes them part of the persistence unit but I can't figure out if that is supposed to work or not. It doesn't appear to work but it isn't clear to me if it is supposed to work.

Thanks again.



jb

_________________
Jeff Brown
brown_j@ociweb.com
Principal Software Engineer
Object Computing Inc.
http://www.ociweb.com/

Autism Strikes 1 in 250
Find The Cause ~ Find The Cure
http://www.jeffandbetsy.net/walkfar2005/
http://www.naar.org/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 5:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7179
Location: Atlanta, USA
hbm autodiscovery is a sugar feature, it is not mandatory to put hbm files in a par.

_________________
Emmanuel
Check Hibernate Search in Action out


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.