[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] If JPA Cache is enabled it's possible to get more Entitys as stored in the underlying database
|
EclipseLink will not verify the integrity of your collection for you prior to
going to the database.
You can likely see this behavior even without the cache just by staying reading
within the same EntityManager as you made the changes - probably in other
persistence providers too.
Some options:
- add business logic to avoid the double add
- refresh the object using either the JPA refresh option or a REFRESH query hint
- configuring the cache to ISOLATED will not completely solve this issue, but
will reduce the likelyhood of you seeing it in other threads
On 14/03/2013 3:00 AM, helmut.at.work wrote:
Strange behavior: If JPA Cache is enabled it's possible to get more Entitys
as stored in the underlying database.
I made an example here: https://github.com/helmut-at-work/test-jpacache
<https://github.com/helmut-at-work/test-jpacache>
Test:
@RunWith(Arquillian.class)
public class ManagerArquillianTest {
@EJB
Manager manager;
....
@Test
public void testOneToManyWithDoubleChildObjects() throws Exception {
System.out.println("Test a simple OneToMany with 1 parent and 3
childs, where 2 childs are the same object.");
ParentNode pdetached = new ParentNode();
ChildNode c1 = new ChildNode();
c1.setParentNode(pdetached);
pdetached.getChilds().add(c1);
ChildNode c2 = new ChildNode();
c2.setParentNode(pdetached);
pdetached.getChilds().add(c2);
//add the same object twice (not sure what happen)
pdetached.getChilds().add(c2);
//What is to be expected? 3 or 2 Rows in database table childnode?
manager.saveParentNode(pdetached);
//Let's see what is in the database with simple SQL
int count = countChildNodes();
//We get 2 rows in childnode!
assertEquals(2, count);
//Ok let's read with jpa and cache active
ParentNode pread = manager.getParentNode();
// I think we should get 2 childnotes now, right?
assertEquals(2, pread.getChilds().size());
//When we disable the cache in persistence.xml this test will pass.
...
Have someone see this before, or see the error I possible made?
--
View this message in context: http://eclipse.1072660.n5.nabble.com/If-JPA-Cache-is-enabled-it-s-possible-to-get-more-Entitys-as-stored-in-the-underlying-database-tp158489.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users