Home » Eclipse Projects » EclipseLink » ReadAllQuery not working for in-memory db(ReadAllQuery not working for in-memory db)
ReadAllQuery not working for in-memory db [message #504753] |
Tue, 22 December 2009 13:10 |
Max WF Poon Messages: 16 Registered: July 2009 |
Junior Member |
|
|
I tried EclipseLink 1.2 & 2.0 with in-memory DB such as HSQLDB 1.8.1 & Derby 10.5.3.0 and found that
1. The in-memory DB contents are only retained and visible during the entityManager session, i.e. between
- em = emf.createEntityManager( )
and
- em.close( )
instead of across multiple em session in an application.
Question: Is this expected behavior? Why?
2 After in-memory db population :
- ReadObjectQuery - e.g. from em.find(Manufacturer.class, <primaryKey>) - is working fine
showing the in-memory db table (e.g. for Manufacturer) was really populated, but
- ReadAllQuery - e.g. from em.createQuery("select object(o) from Manufacturer as o")).getResultList() - always returns null
The following are within the same EntityManager session (no em.close( ) in-between) :-
....
FINEST: PERSIST operation called on: sample.entities.Manufacturer[manufacturerId=19987296].
FINEST: Execute query ReadObjectQuery(referenceClass=Manufacturer sql="SELECT MANUFACTURER_ID, ADDRESSLINE2, ZIP, PHONE, ADDRESSLINE1, FAX, EMAIL, NAME, STATE, CITY, REP FROM MANUFACTURER WHERE (MANUFACTURER_ID = ?)")
INFO: em.find( ) found Manufacturer[19987296]=SimpleJpaToplinkApp.entities.Manufact urer[manufacturerId=19987296]
...
FINEST: Execute query ReadAllQuery(referenceClass=Manufacturer sql="SELECT MANUFACTURER_ID, ADDRESSLINE2, ZIP, PHONE, ADDRESSLINE1, FAX, EMAIL, NAME, STATE, CITY, REP FROM MANUFACTURER
FINEST: reconnecting to external connection pool
FINE: SELECT MANUFACTURER_ID, ADDRESSLINE2, ZIP, PHONE, ADDRESSLINE1, FAX, EMAIL, NAME, STATE, CITY, REP FROM MANUFACTURER
INFO: showAllManufacturers( ): manufacturers=null
This seems to be related to:
org.eclipse.persistence.internal.jpa.EJBQueryImpl.java
protected Object executeReadQuery() {
List parameterValues = processParameters();
// TODO: the following performFlush() call is a temporary workaround for
// bug 4752493:
// CTS: INMEMORY QUERYING IN EJBQUERY BROKEN DUE TO CHANGE TO USE
// REPORTQUERY.
Above not working even if I do
em.setFlushMode(FlushMode.COMMIT)
to avoid flushing, before the ReadAllQuery (2nd one above).
Question: Any way / roadmap EclipseLink JPA Query will work with in-memory ?
Thanks.
|
|
| |
Re: ReadAllQuery not working for in-memory db [message #505918 is a reply to message #504753] |
Tue, 05 January 2010 10:01 |
|
By default EclipseLink uses a connection pool (pool of several JDBC connections). If with your in-memory option each connection is maintaining its own concept of the data, then the connection will not see each others data.
You could try to limit the pool to a single connection. Or you could use a file database so their can be multiple connections.
How are you configuring your connection pool?
Try,
"eclipselink.jdbc.connections.min"="1"
"eclipselink.jdbc.connections.max"="1"
James : Wiki : Book : Blog : Twitter
|
|
|
Re: ReadAllQuery not working for in-memory db [message #506013 is a reply to message #505918] |
Tue, 05 January 2010 18:49 |
Max WF Poon Messages: 16 Registered: July 2009 |
Junior Member |
|
|
Sorry. No. I added to persistence.xml the following but it does not help.
<property name="eclipselink.jdbc.read-connections.min" value="1"/>
<property name="eclipselink.jdbc.read-connections.max" value="1"/>
<property name="eclipselink.jdbc.write-connections.min" value="1"/>
<property name="eclipselink.jdbc.write-connections.max" value="1"/>
Actually, I found that em.persist( ) seems to create the related schema on the in-memory DB only, after which I need to insert the rows into in-memory DB via JDBC :
- executeUpdate(<insert statement>)
then I can retrieve the rows either via
- em.find(...), or JPA-QL i.e.
- em.createQuery(queryStr).getResultList( )
Tracing included as following FYI :
Case I : em.persist( ) followed by em.createQuery(queryStr).getResultList( ) in showAllManufacturers( ) gives the following trace :-
FINEST: PERSIST operation called on: persistenceApp.entities.Manufacturer@130f50e.
.........
FINEST: PERSIST operation called on: persistenceApp.entities.Manufacturer@130fb60.
FINEST: Execute query ReadAllQuery(referenceClass=Manufacturer sql="SELECT MANUFACTURER_ID, ADDRESSLINE2, ZIP, PHONE, ADDRESSLINE1, FAX, EMAIL, NAME, STATE, CITY, REP FROM MANUFACTURER")
FINEST: reconnecting to external connection pool
FINE: SELECT MANUFACTURER_ID, ADDRESSLINE2, ZIP, PHONE, ADDRESSLINE1, FAX, EMAIL, NAME, STATE, CITY, REP FROM MANUFACTURER
FINE: showAllManufacturers(): manufacturers=null
Case II : em.persist( ) followed by JDBC executeUpdate("INSERT IGNORE INTO ...."), followed by em.createQuery(queryStr).getResultList( ) in showAllManufacturers( ) gives the following trace :-
FINEST: PERSIST operation called on: persistenceApp.entities.Manufacturer@130f50e.
...........
FINEST: PERSIST operation called on: persistenceApp.entities.Manufacturer@130fb60.
FINEST: Execute query ReadAllQuery(referenceClass=Manufacturer sql="SELECT MANUFACTURER_ID, ADDRESSLINE2, ZIP, PHONE, ADDRESSLINE1, FAX, EMAIL, NAME, STATE, CITY, REP FROM MANUFACTURER")
FINEST: reconnecting to external connection pool
FINE: SELECT MANUFACTURER_ID, ADDRESSLINE2, ZIP, PHONE, ADDRESSLINE1, FAX, EMAIL, NAME, STATE, CITY, REP FROM MANUFACTURER
FINEST: Register the existing object persistenceApp.entities.Manufacturer@130f50e
...............
FINEST: Register the existing object persistenceApp.entities.Manufacturer@130fb60
FINE: showAllManufacturers(): manufacturers=[persistenceApp.entities.Manufacturer@130f50e,...., persistenceApp.entities.Manufacturer@130fb60]
Again (tested using JavaEE container JDBC connection pool) while JPA-QL seems to work only after explicitly JDBC INSERTs, I can use em.find(....) to retrieve the entity objects in both cases. In summary,
em.persist(...) => can get entities by em.find(...) and within same em session (before em.close( )).
JDBC stmt.executeUpdate("INSERT....") => can get entities by
- em.createQuery(...).getResultList( ), or
- stmt.executeQuery(queryStr)
and across multiple em session, i.e. after em.close( ) and em = emf.createEntityManager( ) again.
[Updated on: Wed, 06 January 2010 04:12] Report message to a moderator
|
|
|
Re: ReadAllQuery not working for in-memory db [message #506507 is a reply to message #504753] |
Thu, 07 January 2010 18:40 |
|
Try,
"eclipselink.jdbc.connections.min"="1"
"eclipselink.jdbc.connections.max"="1"
don't use,
<property name="eclipselink.jdbc.read-connections.min" value="1"/>
<property name="eclipselink.jdbc.read-connections.max" value="1"/>
<property name="eclipselink.jdbc.write-connections.min" value="1"/>
<property name="eclipselink.jdbc.write-connections.max" value="1"/>
this will configure 2 connections, you need to use 1.
(you need to be on at least EclipseLink 1.1)
James : Wiki : Book : Blog : Twitter
|
|
| | | | | |
Goto Forum:
Current Time: Fri Sep 20 23:08:38 GMT 2024
Powered by FUDForum. Page generated in 0.04778 seconds
|