-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to create EntityManagerFactory?
PostPosted: Thu Aug 09, 2007 10:58 am 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
Hey,

I want to create EntityManagerFactory in runtime.

Means, that i dont want to use the persistence.xml file, because i will know the schema name only in runtime.

Any one has a knowledge or an example how to create EntityManagerFactory in my code ?


Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 8:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
use Persistence.createEntityManagerFactory("name", properties)

put hibernate.default_schema in your properties and use persistence.xml for the rest.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: This is exactly the way i do this
PostPosted: Sun Aug 12, 2007 5:56 am 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
In my DS i didnt set the schema.

When the server startup it create a factory based on this persistence unit:

Code:
<persistence>
  <persistence-unit name="BRL-Server">
    <jta-data-source>java:/InsiteDS</jta-data-source>
    <properties>
            <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy" />
    </properties>
  </persistence-unit>
</persistence>


In run time i create factories like the way you suggested
based on this factory with the schema as a parameter.

My questions are:
1. What is the meaning of the first factory? no schema was set for this factory.
2. How can i avoid from create the first facroty. I dont need it. Is there any API that i can craete a facroty in runtime without the need of base factory
3. the factoy that created is no ManagedFactory , so is used this code is this ok?
Code:
         ManagedEntityManagerFactory managedEntityManagerFactory = EntityManagerFactoryMap.getInstance().getManagedEntityManagerFactory(schemaName);
         em = new TransactionScopedEntityManager(managedEntityManagerFactory);


Thank you very much.

ps. i am working with JBoss 4.2


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 15, 2007 9:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The first factory is created because the spec states so. if a persistence.xml if found the factory is deployed.
Of avoiding the deployment is not possible, and Jboss AS does not provide a proprietary way to do that either.

I don't know exactly what ManagedEntityManagerFactory is, but it seems you're messing up with internal JBoss AS classes, so no you can't do that.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 15, 2007 9:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I mean you can but at your own risk :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: I chose to use in this API
PostPosted: Thu Aug 16, 2007 12:35 pm 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
Code:
em = managedEntityManagerFactory.getTransactionScopedEntityManager();


I look at the code and it seems to work.

It success to get the same entity manager in the transaction scope.[/quote]


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