--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cf-orm-dev+...@googlegroups.com.
To post to this group, send email to cf-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/cf-orm-dev.
For more options, visit https://groups.google.com/d/optout.
transaction { //do stuff if (good) { transaction action="commit"; else { transaction action="rollback"; } }
Of course, with that sort of setup and persisting a simple object all works well. The problem I am having is when related objects are introduced and the database error occurs on the child/many (licence) object of the relationship, the persisted parent/one (user) object is not rolled back.
So again in the example I gave above
user is created
licence is created and added to user
user is persisted and as a result the attempt to persist licence is made. This fails at the db end (my forced boolean error).
this causes an exception and licence is not persisted....
here is where I expect user to be rolled back... but it is not.
I know the errors can, and probably should be caught at the object level with the validate and validateparams property attributes etc, but there will always be exceptions. And when they occur, at the database level, within a transaction all persisted data needs to be rolled back.. pretty important for data integrity.
Again I feel like I am missing something here (setup wise perhaps?) as it is such a simple process.
Thanks for your help
Here is Johns one to many relationship example which is basically the same as mine.. even has the same rollback problem!! I added a try catch block for clarity. The results are the same with or without try catch block.
transaction {
try {
// create a new Author
Author = entityNew( "Author" );
Author.setFirstName( "John" );
Author.setLastName( "Whish" );
// create a new Post
Post = entityNew( "Post" );
Post.setTitle( "Post 1" );
Post.setContent( "Lorem ipsum dolor amet." );
Post.setIsPublished(true);
Post.setDatePublished( Now() );
// add the Post to the Author
Author.addPost( Post );
// save the new Author
EntitySave(Author);
} catch(any e) {
transaction action="rollback";
rethrow;
}
}
the above works fine. It creates an Author and Post entry with the correct relationship.
I cause the Post entry to fail at the database level by simply changing
Post.setIsPublished(true); to Post.setIsPublished(""); There is no validation on the isPublished cfc property so the invalid data is accepted at that point. But when persisted the database throws an exception as it needs a bit value for isPublished. Fair enough.. Post entry fails... Author entry does not.. and is not rolledback!
--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cf-orm-dev+...@googlegroups.com.
To post to this group, send email to cf-or...@googlegroups.com.
Visit this group at http://groups.google.com/group/cf-orm-dev.
For more options, visit https://groups.google.com/d/optout.
I already had this.ormsettings.flushAtRequestEnd = false;
I've now added this.ormsettings.automanagesession = false;
It didn't change anything.. but you did put me back in the application settings where I found the problem!! Bit of a weird one really.
Basically setting the datasource username and password in the application.cfc was the problem. So I moved those into cfadmin to fix.
So this application.cfc did NOT allow the rollback.
component {
this.name = "myORMApplication";
this.ormenabled = "true";
this.datasource = {name = 'mydsn', username = "dbuser", password = "dbpwd"};
this.ormsettings.flushAtRequestEnd = false;
this.ormsettings.automanagesession = false;
}
But this one (with cfadmin handling dsusername and dspassword) DOES allow the rollback.
component {
this.name = "myORMApplication";
this.ormenabled = "true";
this.datasource = {name = 'mydsn'};
this.ormsettings.flushAtRequestEnd = false;
this.ormsettings.automanagesession = false;
}
Thanks all for the help.