[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] JPA DAO in Desktop Application

Hello Everyone

I've got one more question and hopefully someone can help me out here, since all tutorials and pages I've found for JPA dont cover the DAO usage. At least not for J2SE environments. In a Container I can just put a @EntityManager annotation on my DAO and everything is fine but I have no clue how I should do this for my RCP.

But maybe I should start by what I already have. EclipseLink is started as rcp-bundle and I can obtain the EntityManagerFactory for my persistence.xml. I am also able to create EntityManger but I dont know what is the right/efficient way for my DAOs.

Do I have to create a EntityManager for each DAO, and does it always has to be a newly created one? Or can I reuse EntityManager-Instances (Singleton anybody ;) ).

Currently I have a Singleton-Class called JpaManager which creates the EntityManagerFactory and this one also creates the DAOs and passes a EntityManager Instance (which is reused). When I run my test I get an exception regarding multiple entities in one session. I found something about a SessionBroker but I am cufused if my approach might be totaly wrong at all (so a SessionBroker will not help me in the end).

Could somebody clarify this a bit for me, and maybe give a best-practise tip?

Thanks in advance
-- Marc