-->
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.  [ 4 posts ] 
Author Message
 Post subject: mapping using .hbm.xml with EntityManager ?
PostPosted: Tue Feb 20, 2007 10:37 pm 
Newbie

Joined: Tue Feb 20, 2007 10:00 pm
Posts: 8
I would like to use external .hbm.xml mapping files with the Java persistence API EntityManager class. (I am trying to use Hibernate with Java source generated by an IDE which currently does not provide a mechanism for user-specified annotations.) I read through the sample chapter of 'Java Persistence' which shows converting the version of the HelloWorld example from using .hbm.xml mappings to using annotations but still using the Hibernate native API. The chapter mentions using .hbm.xml files with the Java persistence API, i.e EntityManager, but I have not been able to find any examples in the hibernate sample directories of this.

I tried to modify a working example to change from org.hibernate.Session to to use javax.persistence.EntityManager but keep my .hbm.xml mappings. I am getting a runtime error of 'Unknown entity'. I added a 'getMappings' method like in the EntityManger examples I have seen. Any suggestions or pointers to example code which uses EntityManager + .hbm.xml mappings ?

Thanks.

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 6:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you show your persistence.xml, this is where the hbm file should be listed (using mapping-file)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 28, 2007 2:38 pm 
Newbie

Joined: Tue Feb 20, 2007 10:00 pm
Posts: 8
This is my persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">

<persistence-unit name="shopvisit">
<properties>
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
</properties>
</persistence-unit>
</persistence>

This is the relevant portfion of my hibernate.cfg.xml:

<mapping resource="shopvisit/PortfolioActiveObject.hbm.xml"/>
<mapping resource="shopvisit/Run.hbm.xml"/>
<mapping resource="shopvisit/RunBatch.hbm.xml"/>
<mapping resource="shopvisit/BatchRunMapping.hbm.xml"/>

</session-factory>

</hibernate-configuration>

This is the error I am getting:
[java] Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: shopvisit.PortfolioActiveObject
[java] at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:185)
[java] at shopvisit.PortfolioManagerNew.getRunBatch(Unknown Source)
[java] at shopvisit.PortfolioManagerNew.main(Unknown Source)
[java] Caused by: org.hibernate.MappingException: Unknown entity: shopvisit.PortfolioActiveObject
[java] at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
[java] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:68)
[java] at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
[java] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
[java] at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
[java] at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)

I have an example working with Hibernate native API + .hbm.xml files using
the same hibernate.cfg.xml file.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 7:16 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I can't really see how this is happening, can you create a test case and post it to JIRA (also attach the logs please)

_________________
Emmanuel


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