Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Ignore Cache on Query

Michael/James,

Is em.flush() the same as committing something?  I'm a little confused,  I want to insert 100 records to a table but want to do it 10 at a time, so I want to call em.persist() 10 times and then call em.flush() after, all in the same method.  I'm in Glassfish and em.flush() doesn't commit anything and all rows are committed at the end of method execution.

I tried setting em.setFlushMode (FlushModeType.COMMIT) but that had no impact.

How do I go about doing this?  I'm developing an application in Seam and they're saying to use Hibernate to take advantage of its  "manual flush" implementation which no other provider has.  Is that really true?

I find it hard to believe that such a core feature is missing.

Thanks,
Zarar



On Fri, Jan 15, 2010 at 8:39 AM, christopher delahunt <christopher.delahunt@xxxxxxxxxx> wrote:
Hello Michael,

The "eclipselink.flush" property is a query hint.  You will need to use "eclipselink.persistence-context.flush-mode" to set the property in persistence.xml.


Best Regards
Chris

Michael Simons wrote:
Hello James,

The eclipselink.flush option does not work like expected.
In the persistence.xml, I specified:
     <property name="eclipselink.flush" value="Commit" />
But this seems to be ignored, because I get the following exception, on a query before anything
was committed:

SCHWERWIEGEND: Exception [EclipseLink-4002] (Eclipse Persistence Services -
1.2.0.v20091016-r5565): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Column set to default
value; NULL supplied to NOT NULL column 'tour_id' at row 1
Error Code: 0
Call: UPDATE tour_position SET tour_id = ?, jdo_version = ? WHERE ((tour_position_id = ?) AND
(jdo_version = ?))
       bind => [null, 7, 96117, 6]
Query: UpdateObjectQuery(net.uniopt.domain.ot.OrderStop@17775)
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence
Services - 1.2.0.v20091016-r5565): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Column set to default
value; NULL supplied to NOT NULL column 'tour_id' at row 1
Error Code: 0
Call: UPDATE tour_position SET tour_id = ?, jdo_version = ? WHERE ((tour_position_id = ?) AND
(jdo_version = ?))
       bind => [null, 7, 96117, 6]
Query: UpdateObjectQuery(net.uniopt.domain.ot.OrderStop@17775)
       at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:612)
       at org.eclipse.persistence.internal.jpa.EJBQueryImpl.performPreQueryFlush(EJBQueryImpl.java:1153)
       at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:371)
       at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:636)
       at de.optitool.biz.tp.StockManager.queryFirstAndRecentDetection(StockManager.java:786)
       at de.optitool.biz.tp.StockManager.retrieveRemainingContingentStock(StockManager.java:359)
       at de.optitool.biz.tp.StockManager.tell(StockManager.java:344)
       at de.optitool.biz.tp.ReservationManager.bookOnAbstractCont(ReservationManager.java:1064)
       at de.optitool.biz.tp.ReservationManager.bookOnCheapestProduct(ReservationManager.java:1318)
       at de.optitool.biz.tp.ReservationManager.reserveStocks(ReservationManager.java:542)
       at de.optitool.biz.tp.ReservationManager.reserveStocks(ReservationManager.java:466)
       at de.optitool.biz.tp.ResAllocController.processTour(ResAllocController.java:217)
       at de.optitool.biz.tp.ResAllocController.runTask(ResAllocController.java:141)
       at de.optitool.biz.tp.ResAllocController.runOnEntities(ResAllocController.java:78)
       at de.optitool.biz.tp.TourModificationManager.runControllers(TourModificationManager.java:595)
       at net.uniopt.ot.action.UnplanOrders.runOnEntities(UnplanOrders.java:70)
       at de.optitool.action.UserRestrictedAction.run(UserRestrictedAction.java:134)
       at net.uniopt.ot.action.TaskAction.run(TaskAction.java:124)
       at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
       at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
       at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
       at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
       at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
       at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
       at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
       at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
       at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
       at org.eclipse.jface.window.Window.open(Window.java:801)
       at net.uniopt.ot.gui.MainWindow.open(MainWindow.java:566)
       at net.uniopt.app.Application.processEventLoop(Application.java:514)
       at net.uniopt.app.Application.run(Application.java:214)
       at net.uniopt.ot.Main.main(Main.java:49)

Any hints what might be wrong here are appreciated.

- Michael

James Sutherland schrieb:
 
Do you want to ignore the cache, or not do the flush?

To disable flushing, you can either set the EntityManager flushMode, or
persistence unit property or use the query hint,

"eclipselink.flush"="Commit"

This will prevent to auto flush.

If you truly wish to ignore the cache, and build "detached" objects directly
from the database, you can use,

"eclipselink.maintain-cache"="false"

The hint, QueryHints.CACHE_USAGE, CacheUsage.DoNotCheckCache, just means
that a query will not check the cache before accessing the database, the
query will still flush, and will still use the cache and persistence context
when building the objects from the database result.


Michael Simons wrote:
   
Hello,

How can I tell EL to ignore the cache when executing a query, so there's
no flush done before
executing the query?
Is this done by query.addHint(QueryHints.CACHE_USAGE,
CacheUsage.DoNotCheckCache) ?

- michael


     
-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , http://wiki.oracle.com/page/TopLink TopLink Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , http://www.nabble.com/EclipseLink-f26430.html EclipseLink Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence    

 
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



--
Zarar Siddiqi
416-737-9024

Back to the top