2

My application comprises three layers being:

  • Interaction layer (RestServices JAX-RS)
  • Business layer (Stateless EJBs)
  • Persistence layer (DAO's with queries etc.)

In addition I have this domain objects layer which runs through the layers. The application was first setup to use a nosql database, but we had to abandon that. Now we are using JPA with a RDBMS but running into trouble when migrating, mainly due to the fact that the jaxb objects that the interaction layer is using, is trying to lazily load domain objects without a transaction when the are serialized. This transaction has been closed once it returned from the stateless ejb.

After reading a lot on the web, I tried to annotate my restservice with @Stateless too in order to start a transaction a bit sooner and to avoid the transaction being closed once the business layer has been left. Unfortunately this doesn't work either as I still getting lazilyinitializationexceptions.

So my question is how should I combine JAXB, JAX-RS and EJB's in order to avoid the LIException?

regards

Michael

Michael
  • 233
  • 2
  • 4
  • 11
  • Sorry for the short answer. See if any of this helps [How to solve lazy initialization exception using JPA and Hibernate as provider](http://stackoverflow.com/questions/578433/how-to-solve-lazy-initialization-exception-using-jpa-and-hibernate-as-provider) – K.Nicholas Oct 01 '14 at 17:49
  • Hi Nicholas, this is not really what I'm looking for. It's seems a kind of a hack. – Michael Oct 03 '14 at 06:28
  • You can inject your ejb to rest service this way: `@EJB private YourService service;`. Don't sure I understood your question correctly. – Everv0id Dec 15 '14 at 07:47

1 Answers1

0

In order to avoid lazily initialization exceptions the simplest way is to create DTOs of the entities which will contain the desired values and pass them to the interaction layer. In this way no initialization exceptions will be thrown and also the data model will contain all the info you want.

fotis
  • 145
  • 1
  • 7