Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

detach hibernate objects

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

In 3 tier application we have the facade, business, dao layers.
I want that the dao will return detached objects.

The transaction is open in the facade , so change in the facade or the businees layer to the objects which has been return by the dao will persist the change and i dont want changes that are not done through the dao layer.

the idea that i think on them is cloen the objects (but this is required to go over the object graph)
or set the dao transaction scope to new transaction.

any other ideas?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the Facade your UI? JSP? Usually Transaction boundaries are best set at the Service/Business logic sections.

Mark
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The facade is the service layey - stateless bean.

The question is where the transaction start - in the first time i do a db action or when i call explicity to userTransaction.begin or implicity by having transaction annotation...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
avihai marchiano wrote:The facade is the service layey - stateless bean.

The question is where the transaction start - in the first time i do a db action or when i call explicity to userTransaction.begin or implicity by having transaction annotation...


OK, I got confused when you had facade and business seperate, but I haven't used EJBs in a long time, so what you have is perfect. and yes the Facade is the transaction boundary. The Facade is the interface to the outside world and represents each use case and transactions should be bound at the use case, service layer. That way if your service has to call mutliple DAOs/Repositories, they will all be within the same transaction, since you want it that way. If any one of the queries fail, then you want the whole use case to fail (in most cases), you want the whole use case to be Atomic.

Hope that helps

Mark
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you , but this is not the question.


The question is how to detach hibernat entities.

you have layer AAA - > call layer BBB - > call layer CCC - > call DAO.

i dont want that the dao will return attach objects.

This break layering, i want to detach the hibernate objects before the DAO return them to the caller layer.

You can do this by:
clone the object
limit the dao transaction scope.

but i dont love any of the idea above.
My quesion is - if you have any idea how to detach the hibernate objects?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic