Lukas, thanks for the prompt and detailed answer!
Cheers, Andras On 2010 Mar 26, at 17:15, Lukas Lang wrote: > Hey Andras, > > great to see another group of students participating! > > Regarding your question: > After committing the first transaction, the object's state is transferred to > the database (eventually flushed), the transaction cache is invalidated and > the object tracker (which identifies changes within objects) stops > "following" the Person instance. In terms of JPA: It becomes detached. > > When starting the second transaction, Castor (the running transaction in > specific) has no clue that your Person instance wants to contribute to that > transaction (Imagine Castor keeping references to all objects someone had > loaded from the database earlier would not be such a good idea, especially > from the garbage collection's point of view and concerning database locks > etc.). > > However, you have two options: > > 1) Load the entity, then modify it and then commit the transaction. > 2) Explicitly calling Database.update using Long Transactions as described in > [1]. > > I hope that all your questions are now answered. Feel free to follow up, if > not. > > Regards, > Lukas > > PS: One more thing: ad "persisted value remains the same". Always perform a > flush first, because it simply may have not been flushed! > > [1] Long Transactions, http://castor.org/long-transact.html > > Am 26.03.2010 um 16:39 schrieb Andras Hatvani: > >> Hi, >> >> I'm new to Castor and I'm part of this semester's development team of the >> course Advanced Software Engineering on the Vienna University of Technology. >> During the development with Castor the following question arose for me: Why >> must the load and the updating of an object be in the same transaction? >> >> Example: >> 1) WORKS >> db.begin(); >> loadedPerson = db.load(Person.class, id); >> loadedPerson.setFirstName(FIRST_NAME_2); >> db.commit(); >> >> 2) DOESN'T WORK >> db.begin(); >> loadedPerson = db.load(Person.class, id); >> db.commit(); >> >> db.begin(); >> loadedPerson.setFirstName(FIRST_NAME_2); >> db.commit(); >> >> In the second case the persisted values remained the same. >> >> Thanks, >> Andras Hatvani >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

