Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forums2 same queries => different results?
https://www.eclipse.org/forums/index.php/mv/msg/126179/387364/#msg_387364
I try to invoke the same query twice and I didn't get same results?!
What could be wrong (see source code and output below)?
I tried to disable Query Cache but still different results...
I am using EclipseLink 2.0.0 Milestone Build.
Thanks a lot for your help.
andiqo
//-- source code
Query query1 = em.createQuery("SELECT o FROM Node o WHERE o.name = :name");
query1.setParameter("name", "w1");
List<?> results1 = query1.getResultList();
System.out.println("** results1.size is: " + results1.size());
Query query2 = em.createQuery("SELECT o FROM Node o WHERE o.name = :name");
query2.setParameter("name", "w1");
List<?> results2 = query2.getResultList();
System.out.println("** results2.size is: " + results2.size());
//-- output
[EL Fine]: 2009-04-18
12:42:02.684--ServerSession(485367518)--Connection(148503708 9)--Thread(Thread[main,5,main])--SELECT
ID, VERSION, NODETYPE_ID FROM NODE WHERE (NAME = w1)
** results1.size is: 1
[EL Fine]: 2009-04-18
12:42:04.329--ServerSession(485367518)--Connection(20566293) --Thread(Thread[main,5,main])--SELECT
ID, VERSION, NODETYPE_ID FROM NODE WHERE (NAME = w1)
** results2.size is: 0]]>andiqo 2009-04-18T10:50:02-00:00Re: 2 same queries => different results?
https://www.eclipse.org/forums/index.php/mv/msg/126179/387368/#msg_387368
Your log shows the same SQL being generated. Is another user/thread
deleting the row from the database? Try doing the same through JDBC,
perhaps something odd is occurring with your driver or database. What
database and driver are you using? Is it just this query, or do other
queries have the same effect?
---
James http://www.nabble.com/EclipseLink---Users-f26658.html]]>James Sutherland2009-04-20T14:09:14-00:00Re: 2 same queries => different results?
https://www.eclipse.org/forums/index.php/mv/msg/126179/387371/#msg_387371
state of the Entities? What properties have you set when creating the
EntityManager?
Based on the log the Entity Manager is joining the active transaction and
using the transactional connection for the second query which results in
different data.
--Gordon]]>Gordon Yorke2009-04-20T15:04:02-00:00Re: 2 same queries => different results?
https://www.eclipse.org/forums/index.php/mv/msg/126179/387381/#msg_387381
I could investigate a little more this morning. Below is my test class and
my properties. I am using PostgreSQL 8.3.7 on x86_64-pc-linux-gnu with
jdbc driver: 8.3-604.jdbc4.
In fact, I could have my test pass changing my setupClass() method as
follow:
@BeforeClass
public static void setupClass() throws Exception {
em = emf.createEntityManager();
Assert.assertTrue(em.isOpen());
// Should read table names from output.sql
em.createNativeQuery("delete from EDGE").executeUpdate();
em.createNativeQuery("delete from NODE").executeUpdate();
em.createNativeQuery("delete from NODEFIELD").executeUpdate();
em.createNativeQuery("delete from NODEPROPERTY").executeUpdate();
em.createNativeQuery("delete from NODEREVISION").executeUpdate();
em.createNativeQuery("delete from NODETYPE").executeUpdate();
em.createNativeQuery("delete from PROPERTY").executeUpdate();
em.createNativeQuery("delete from
PROPERTY_NODETYPE").executeUpdate();
em.createNativeQuery("delete from SPLITBLOB").executeUpdate();
em.createNativeQuery("delete from SPLITBLOBPART").executeUpdate();
@AfterClass
public static void teardownClass() {
if (em != null) {
txCommit(em);
em.close();
em = null;
}
}
@Before
public void setupMethod() {
txBegin(em);
}
@After
public void teardownMethod() {
txCommit(em);
}
@Test
public void testJpql() throws Exception {
Query query1 = em.createQuery("SELECT o FROM Node o WHERE o.name =
:name");
query1.setParameter("name", "root");
List<?> results1 = query1.getResultList();
int s1 = results1.size();
Query query2 = em.createQuery("SELECT o FROM Node o WHERE o.name =
:name");
query2.setParameter("name", "root");
List<?> results2 = query2.getResultList();
int s2 = results2.size();
Assert.assertEquals(s1, s2);
System.out.println("** results1.size is: " + results1.size());
System.out.println("** results2.size is: " + results2.size());
}
}
<property name="eclipselink.query-results-cache" value="true" />
<property name="eclipselink.query-results-cache.expiry" value="100000" />
<property name="eclipselink.query-results-cache.size" value="1000" />]]>andiqo 2009-04-25T09:04:42-00:00Re: 2 same queries => different results?
https://www.eclipse.org/forums/index.php/mv/msg/126179/387426/#msg_387426
the isolation level setting before populate interferes with the read
queries. Have you attempted to use straight JDBC to test this isolation
level with your database? Start transaction by setting autocommit to
false, insert data and then execute 2 queries. It is possible, although
unexpected, that the isolation level is causing the second query to not
see the transactional updates.
--Gordon]]>Gordon Yorke2009-04-28T15:28:04-00:00