Escolar Documentos
Profissional Documentos
Cultura Documentos
Password (Reset):
Login
Register
Members
Search...
Find
Home
Why Seam?
Community > Forums > Seam Users > entityManager persist with manual ...
Seam 2
Getting Started Downloads Documentation
Forum List
Topic List
Seam 3
Contribute Downloads Documentation Compatibility Tooling Solder Catch Module Config Module Cron Module Drools Module Faces Module Errai CDI International Module JCR Module JMS Module Mail Module Persistence Module Remoting Module Reports Module REST Module Security Module Servlet Module Social Module Spring Module Validation Module Wicket Module Module Handbook
Is there any way to do entityManager.persist(myEntity) and not automatically persist the entity to the database? I have this code, but isn't working as I spec to:
Conversation.instance().begin(true,false); Conversation.instance().changeFlushMode(FlushModeType.MANUAL); entityManager.persist(entity);
9 Replies:
Could it be done? My first approach was to make entityManager work in MANUAL flush mode, so I could do something like this:
Conversation.instance().begin(true,false); Conversation.instance().changeFlushMode(FlushModeType.MANUAL); ... entityManager.persist(object1); ... entityManager.persist(object2); ... entityManager.flush(); Conversation.instance().end;
Weld
Downloads Documentation Development
Community
Forums CDI Extensions Contribute JIRA Mailing Lists Events Links Seam In Production
With this approach, I spec that when I do entityManager.flush(); it automatically start a transaction, flush all changes to da commit the transaction if every thing was ok. But the problem it doesn't work like I suppose to do, entityManager.persist(ob persisted automatically to the database and don't wait for entity.flush(). Any help? Regards, Chiara
Documentation
FAQs Knowledge Base Design
There are other ways to get a reference to the entityManager that will cause behavior similar to what you talking about.
13. Aug 2009, 21:56 America/Ne J
I cannot use @In because It need to be marked as @BypassInterceptors Here is Why I'm using this approach: http://seamframework.org/Community/JavaBeanInterceptorAndObjectInternalState
In main(), the insert commits, so I was able to reproduce your problem. Likely due to using @Id with @GeneratedValue in y class. The 2nd example below (update) only commits if I add the em.flush().
@Name("conversationAPI") @Scope(ScopeType.CONVERSATION) public class TestConversationAPI { @Logger Log log; @Transactional public void main() { EntityManager entityManager = (EntityManager) Component.getInstance("em"); Conversation.instance().begin(true,false); Conversation.instance().changeFlushMode(FlushModeType.MANUAL); Hotel hotel = new Hotel(); hotel.setName("fooname"); hotel.setAddress("fooaddress"); hotel.setCity("foocity"); hotel.setState("foostate"); hotel.setZip("foozip"); hotel.setCountry("USA"); entityManager.persist(hotel); //entityManager.flush(); Session session = (Session) entityManager.getDelegate(); log.info("session.getFlushMode() = "+session.getFlushMode()); } @Transactional public void main2() { EntityManager entityManager = (EntityManager) Component.getInstance("em"); Conversation.instance().begin(true,false); Conversation.instance().changeFlushMode(FlushModeType.MANUAL); Hotel hotel = entityManager.find(Hotel.class, new Long(1)); hotel.setAddress("1234 Arbi St."); //entityManager.flush(); Session session = (Session) entityManager.getDelegate(); log.info("session.getFlushMode() = "+session.getFlushMode()); }
I'm learning Objective-C, it's about time I learned an OO language other than Java!
This is exactly me problem, another thing to add to it is that if you are using EntityHome and you perform an update before entityManager.flush, it will flush the update to db.
@Name("conversationAPI") @Scope(ScopeType.CONVERSATION) public class TestConversationAPI { @Logger Log log; @Transactional public void main3() { EntityManager entityManager = (EntityManager) Component.getInstance("em"); HotelEntityHome hotelEntityHome = (HotelEntityHome ) Component.getInstance("hotelEntit Conversation.instance().begin(true,false); Conversation.instance().changeFlushMode(FlushModeType.MANUAL);
hotelEntityHome.setId((long) 1); hotelEntityHome.getInstances().setName("Name Changed"); hotelEntityHome.update(); Session session = (Session) entityManager.getDelegate(); log.info("session.getFlushMode() = "+session.getFlushMode()); } }
I'm not very interested in SAF, it was just another similar behavior that I found, but for the initial problem: auto flush of entityManager.persist(object) with flush mode MANUAL, do you have any solution? anyone else that could help us? Regards, Chiara
are you using @Id with @GeneratedValue (IDENTITY, not sequences) in your entity class(es)? An auto-generated identity c cause a commit even if you don't call flush() manually. This is covered in SiA book.
I'm learning Objective-C, it's about time I learned an OO language other than Java! Rating:
I will change it and try again. Thanks a lot! PD: Sory for the late reply, I am from Argentina and yesterday was a holiday.
Copyright 2009, Red Hat Middleware, LLC. All rights reserved. JBoss and Seam are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]