Find after persist - ignoring cache [message #810028] |
Wed, 29 February 2012 10:35  |
Eclipse User |
|
|
|
I have an entity Foo with an eager manytoone relationship with Boo. I run the following code and the System.out shows null:
em.getTransaction().begin();
Foo f = new Foo();
Boo b = new Boo();
b.setId(5659);
f.setBoo(b);
em.persist(f);
Foo fret = em.find(Foo.class, f.getId());
System.out.println(f.getBoo().getName());
em.getTransaction().commit();
The find method brought de Foo object from the cache, I wished a new query was execute bringing all the propeties of the Boo.
Even If I replace the find by the following query the result is the same:
Query q = em.createQuery("SELECT f from Foo f where f.id = " + f.getId()).setHint(QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache);
Foo fret = (Foo) q.getSingleResult();
If I make the query or the find after the commit, the content of the property name of Boo is shown as expected.
How can I have the same behaviour before executing the commit?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03977 seconds