2

My application is using Spring 2.5, and native TopLink 10g. I want to migrate my application from native TopLink to EclipseLink.

Currently each DAO in my application extends TopLinkDaoSupport.java (in Spring 2.5), in order to use the #getSession() method for all DB operations, but the return type of the method is oracle.toplink.sessions.Session instead of org.eclipse.persistence.sessions.

Is there any solution of said problem?

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
Sunny
  • 174
  • 7
  • Why aren't you using the JPA API? That way, you could just simply inject an `EntityManager` to you DAOs. – meskobalazs Feb 09 '15 at 15:00
  • yes, I can. But JPA required to much changes/efforts as each DAO extensively using getTopLinkTemplate() method for reading records from DB. – Sunny Feb 10 '15 at 07:40
  • You should use `JpaDaoSupport` then, though I don't know how extensive changes are needed. I would definitely would go the `EntityManager` way, especially if I would migrate to the reference implementation of JPA 2 :) – meskobalazs Feb 10 '15 at 07:51

1 Answers1

1

I would also recommend to use JPA instead of the old TopLink API. If you really need access to Session object, you can get it from EntityManager too. Check org.eclipse.persistence.internal.jpa.EntityManagerImpl in EclipseLink - this is a class that implements EntityManager. There is a getDelegate() method implemented that returns this (EntityManagerImpl) so ((org.eclipse.persistence.jpa.JpaEntityManager)[EntityManager].getDelegate()).getActiveSession() gives you org.eclipse.persistence.sessions.Session.

George Netu
  • 2,758
  • 4
  • 28
  • 49
Tomas Kraus
  • 466
  • 2
  • 6
  • Can I use existing “toplink-mapping.xml, and session.xml” in JPA or I have to redefine all my entities in persistence.xml, – Sunny Feb 11 '15 at 07:51
  • Yes you can use the existing mapping files. See https://wiki.eclipse.org/Creating_EclipseLink_Files_for_Deployment_(ELUG)#JPA_Applications_and_Session_Metadata – Chris Feb 11 '15 at 14:59