How to obtain connection from EntityManagerFactory? [message #517893] |
Tue, 02 March 2010 08:19  |
Eclipse User |
|
|
|
How do I obtain a connection handler for the underlying connection made by the EntityManagerFactory?
I'm writing an desktop app and need to access the dB. My persistence unit uses an embedded url connection.
Currently I do this by starting JavadB in server mode and get another separate connection on port 1527 as follows:-
// Start JavadB in server mode
try {
server = new NetworkServerControl();
server.start(new PrintWriter(System.out, true));
} catch (Exception ex) {
Logger.getLogger(CBTv01View.class.getName()).log(Level.SEVERE, null, ex);
}
//Get connection to above server
ClientDataSource ds = new ClientDataSource();
ds.setPortNumber(1527);
ds.setDatabaseName(dbName1);
try {
conn = ds.getConnection();
} catch (SQLException ex) {
Logger.getLogger(CBTv01View.class.getName()).log(Level.SEVERE, null, ex);
}
The above approach can be useful in development as you can connect to the dB from debug apps etc. However, it seems expensive on resources for deployment and I would like to reuse the connection the EntityManagerFactory has made.
Thanks,
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07596 seconds