SelectQuery is actually a query to database, so viewing not-yet-inserted objects with it is not possible. See recent discussion: http://cayenne.markmail.org/search/%20list:org.apache.cayenne.user#query:%20list%3Aorg.apache.cayenne.user+page:2+mid:6bwqse4t4czj73zq+state:results
2010/10/15 Borut Bolčina <borut.bolc...@gmail.com> > Hello Mathias, > > context is similar to session in hibernate, but much better. The context is > where your persistent objects live in any of their possible state ( > http://cayenne.apache.org/doc30/persistent-object-lifecycle.html). > > You are trying to rollback database changes made in previous step. This is > not what context.rollback() does. See last paragraph at > http://cayenne.apache.org/doc30/dataobject-state-management.html. > > When you do context.commit, you hit the database (or cache) if there are > any > changes in the object graph you created or modified in the context you are > trying to commit. > > What do you mean by: "How can I do some local changes to the dataset > without > having to commit them to the database?" > > Cheers, > Borut > > 2010/10/15 Mathias Clerc <tlarhi...@gmail.com> > > > Hello, > > > > I am making an evaluation of Cayenne and other frameworks. > > > > One of my test is the following : > > > > begin a set of operations > > make a select * on one table > > insert new element in that table > > make another select * on that table (see that new element along with > > the previous results) > > rollback > > make another select * on that table (see that it came back to it's > > original state) > > > > > > I am using the following code : > > ObjectContext context1 = DataContext.createDataContext(); > > SelectQuery querySelectAll = new SelectQuery(Principal.class); > > System.out.println("-test pre"); > > for (Object out : context1.performQuery(querySelectAll)) { > > System.out.println(((Principal) out).getName()); > > } > > > > Principal newPrincipal = context1.newObject(Principal.class); > > newPrincipal.setName("toto"); > > context1.registerNewObject(newPrincipal); //Same with or > > without this line > > > > SelectQuery querySelectAll2 = new SelectQuery(Principal.class); > > System.out.println("-test post"); > > System.out.println("--c1"); > > for (Object out : context1.performQuery(querySelectAll2)) { > > System.out.println(((Principal) out).getName()); > > } > > System.out.println("--new context"); > > for (Object out : > > DataContext.createDataContext().performQuery(querySelectAll2)) { > > System.out.println(((Principal) out).getName()); > > } > > > > context1.rollbackChanges(); > > System.out.println("-test post rollback"); > > SelectQuery querySelectAll3 = new SelectQuery(Principal.class); > > System.out.println("--c1"); > > for (Object out : context1.performQuery(querySelectAll3)) { > > System.out.println(((Principal) out).getName()); > > } > > System.out.println("--new context"); > > for (Object out : > > DataContext.createDataContext().performQuery(querySelectAll3)) { > > System.out.println(((Principal) out).getName()); > > } > > > > And the output is : > > -test pre > > domain > > administrators > > admin > > -test post > > --c1 > > domain > > administrators > > admin > > --new context > > domain > > administrators > > admin > > -test post rollback > > --c1 > > domain > > administrators > > admin > > --new context > > domain > > administrators > > admin > > > > I think I have not understood completely what a context is. > > My question is in "test post" "c1" (created new element "toto", not > > commited, query done in the new element's context) shouldn't my new > > element appear ? > > If I do a commit on context1 then my element is visible, but it also > > hit the table. > > > > In case that behaviour is normal, how can I do some local changes to > > the dataset without having to commit them to the database ? > > > > Thank you, > > > > Tlarhices > > > -- Andrey