Hello,
I want to know if it is possible to create an instance of EntityManager
using the connection properties(i.e not only Username and Pwd but also
ConnectionURL and jdbc driver).
In other words, I want to use EntityManager for each user session and close
it when the user logs out. I know this is out of place but I dont want to
implement any sort of pooling.
The ideal architecture would be to create an instance of
EntityManagerFactory(when Tomcat starts) in application scope. Further I
want to use this factory to create an EntityManager when a user logs in.
Any ideas if it is possible or not?
I implemented a simple DataSource interface which returns a
java.sql.Connection object.
In my persistence.xml this code works :
<property name="openjpa.ConnectionDriverName" value="util.myDataSource"/>
<property name="openjpa.ConnectionFactoryProperties"
value="PrettyPrint=true,PrettyPrintLineLength=80"/ >
<property name="openjpa.Log" value="DefaultLevel=TRACE,Tool=TRACE"/>
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("JPATest");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Now I want to port the code into my classes :
EntityManagerFactory emf = Persistence.createEntityManagerFactory(null);
Map myProperties = new HashMap();
myProperties.put("openjpa.ConnectionDriverName","util.myDataSource");
myProperties.put("openjpa.ConnectionFactoryProperties","PrettyPrint=true,
PrettyPrintLineLength=80");
EntityManager em = emf.createEntityManager(myProperties);
em.getTransaction().begin();
But it throws the following excpetion :
Exception in thread "main" <4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or
DataSource class name must be specified in the ConnectionDriverName
property.
thx,
Jan
--
View this message in context:
http://www.nabble.com/Configure-EntityManager-with-dynamic-connection-tf4074808.html#a11580724
Sent from the OpenJPA Users mailing list archive at Nabble.com.