-->
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: Adding annotated classes to non-custom EntityManagerFactory
PostPosted: Thu Nov 20, 2008 5:33 pm 
Newbie

Joined: Thu Nov 20, 2008 5:25 pm
Posts: 2
Hi Guys,

I'm working in an environment where each client has your own database schema, but all of them with the same tables.

To use JPA(w/ hibernate behind the scenes) I'm creating the EntityManagerFactory using Ejb3Configuration.

So far so good, but I have a lot of classes, all of them mapped in my persistence.xml file.

I would like to know if it is possible to use the addResource method(of Ejb3Configuration class) to include the mapped classes in my EntityManagerFactory.

I tried it, but without success.

I'm receiving a message that indicates that my classe is not mapped

Code:
Unknown entity: br.com.netsar.model.entity.MasterCountry


I believe that it is occurring because the Ejb3Configuration was not able to read my persistence.xml file (no exception nor logging), I saw that is possible to use orm.xml as configuration resource.

I would like to know if I can do it with persistence.xml.

Thanks for your time,

Pedro

_________________
SCWCD
SCJP

Pedro Henrique Lobato Sena


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 2:39 pm 
Newbie

Joined: Thu Nov 20, 2008 5:25 pm
Posts: 2
I created, just for test, a hibernate.cfg.xml file and I made the mapping of my class

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC 
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
      <mapping class="br.com.netsar.model.entity.MasterCountry" />
   </session-factory>
</hibernate-configuration>


I added the this xml file to my Ejb3Configuration:

Code:
Properties prop = new Properties();
      prop.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
      prop.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
      prop.put("hibernate.connection.username", "root");
      prop.put("hibernate.connection.password", "");
      prop.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/travelne_global");
      prop.put("hibernate.show_sql", "true");
      
      Ejb3Configuration conf = new Ejb3Configuration();
      
      EntityManagerFactory emf = conf.addProperties(prop).addResource("META-INF/hibernate.cfg.xml").buildEntityManagerFactory();


But i received the same error:

Code:
Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: br.com.netsar.model.entity.MasterCountry
   at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:186)
   at br.com.netsar.infra.repository.jpa.MultiDatabaseEntityManagerFactory.main(MultiDatabaseEntityManagerFactory.java:49)
Caused by: org.hibernate.MappingException: Unknown entity: br.com.netsar.model.entity.MasterCountry
   at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:580)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:91)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:842)
   at org.hibernate.impl.SessionImpl.get(SessionImpl.java:835)
   at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:175)
   ... 1 more


What am I missing ?

Thanks

_________________
SCWCD
SCJP

Pedro Henrique Lobato Sena


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.