Hibernate version:2.1.7c
I have an application which useses DTOs to carry data from one layer to the other. This is the problem I encounter:
My DTO arrives in the business layer. The DTO contains data to an existing parent and information on a new child:
1. I start a transaction
2 I use the information in the DTO to retrieve the parent from the databes (the parent is linked to the session)
3 I use the DTO to create a new child object and add the child to the collection of the parent
4 I use the information of the parent and child (the actual hibernate classes) to create a new DTO and send it to my client
5. I commit the tansaction. Because of the cascading update function, Hibernate will automtically save the child in the database.
The problem I have is that I cannot correctly fill the DTO in step 4, because one of the attributes i want to send back is the ID. For the child object this ID is not filled out yet. It will only be generated in step 5.
I cannot really change the location of the commit since this is hidden from me it is done automatically in a ancester class (I believe you would have a similar problem if you use cmt in a session bean).
Is there a way around this problem without doing a explict hibernate call (session.flush()), perhaps a configuration option I've missed.
thnaks for your respone
|