Using a transaction will of course roll everything back, so if what you are
doing with obj1 is related to what you are doing in obj2, as often would be
the case in production code where obj1 is related to obj2, then wrap it all
in a transaction, like so:
// Code2 :
transaction {
obj1 = EntityLoadByPk(‘myclass’, 1);
obj1.myvalue = ‘hello’;
obj2 = EntityLoadByPk(‘myclass’, 2);
obj2.myvalue = ‘bye’;
}
I’ve run into difficulty loading an object outside of a transaction and
then persisting it within a transaction, as in your Code2. Hence my
practice is to wrap an entire load, set, persist cycle in a single
transaction, and usually I’ll include commit and rollback statements within
it so that I can better handle the cases where I might want to do either.
Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland
+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamediaOn Wed, Sep 16, 2015 at 9:26 AM, David Sedeño <@David_Sedeno> wrote:
Hi,
What is the difference between:
// Code 1:
obj1 = EntityLoadByPk(‘myclass’, 1);
obj1.myvalue = ‘hello’;
obj2 = EntityLoadByPk(‘myclass’, 2);
obj2.myvalue = ‘bye’;
ORMFlush();
// Code2 :
obj1 = EntityLoadByPk(‘myclass’, 1);
obj1.myvalue = ‘hello’;
obj2 = EntityLoadByPk(‘myclass’, 2);
transaction {
obj2.myvalue = ‘bye’;
}
(both with flushatrequestend = false).
AFAIK, the two codes persist the both objects data to DB, so, what is the
correct way or the difference between the two methods ?
Thanks
David Sedeño
–
See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your
ticket NOW - http://www.cfcamp.org/
You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/ba5d0093-4bdc-446b-a77c-a193fa42b263%40googlegroups.com
https://groups.google.com/d/msgid/lucee/ba5d0093-4bdc-446b-a77c-a193fa42b263%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.