Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to integrate EclipseLink into existing Client/Server application ?
How to integrate EclipseLink into existing Client/Server application ? [message #523175] Thu, 25 March 2010 08:46 Go to next message
Roger Gilliar is currently offline Roger Gilliar
Messages: 40
Registered: March 2010
Member
I would like to replace our homemade persistence layer with EclipseLink. The problem I currently have is how to incrementally integrate it in our existing application.

Example:

- User saves data on a data entry form. This starts a transaction using some old JBuilder components.

- a beforePost event is generated and triggers the update of some other data. This update is currently done with a very simple persistence layer wich I would like to replace with EclipseLink. But it seems that EclipseLink needs its own transaction. Is it possible that EclipseLink just executes the SQL without starting its own transaction ?

Regards
Roger


Re: How to integrate EclipseLink into existing Client/Server application ? [message #523293 is a reply to message #523175] Thu, 25 March 2010 15:18 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

If you are using JTA, or Spring, then EclipseLink would just join the existing transaction.

Otherwise, you will need a way to force the JDBC connection that EclipseLink is using to be you existing one. The DatabaseLogin option setUsesExternalTransactionController() will make EclipseLink not begin a transaction, but the bigger issue is getting it to use the same connection. You will most likely need to create your own ConnectionPool, or hammer the DatabaseAccessor into the EclipseLink ClientSession.


James : Wiki : Book : Blog : Twitter
Re: How to integrate EclipseLink into existing Client/Server application ? [message #523557 is a reply to message #523293] Fri, 26 March 2010 16:15 Go to previous message
Roger Gilliar is currently offline Roger Gilliar
Messages: 40
Registered: March 2010
Member
Thanks four your answer. I tried to use setUsesExternalTransactionController() but couldn't see any difference. At least a em.getTransaction().begin(); and em.getTransaction().commit seem to behave as before.

After that I tried the following which seems to work, but I'm not sure if this will cause any side effects.

Regards
Roger

  
	List<Vkprlist> vks = Vkprlist.getData();

	EntityManagerFactory emf = Persistence
				.createEntityManagerFactory("test2");
	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	Connection con = em.unwrap(Connection.class);

        // do some JDBC processing

	for (Vkprlist vk : vks) {
			em.merge(vk);
	}
		
			
	em.flush();

        // do some JDBC processing
		
	try {
		con.commit();
		} catch (SQLException e) {
		e.printStackTrace();
	}

	em.close();

Previous Topic:Duplicate aliases generated for columns (1.1.3)
Next Topic:entitymanager.close() doesn't destroy persistence context in SE application
Goto Forum:
  


Current Time: Sat Apr 19 06:11:18 EDT 2014

Powered by FUDForum. Page generated in 0.02015 seconds