java - JPA (hibernate) does not insert on persist, needs to be flushed -


i have stateless bean observes event , saves record:

@stateless public class manager {     @inject     repository repository;      manager() {}      @inject     manager(repository repository) {         this.repository = repository;     }      public void eventhandler(@observes myevent myevent) {         save(event.obj);     }      private save(object object) {         repository.add(object);     } } 

my repository this:

@stateless public class repository {     @persistencecontext     entitymanager em;      repository() {}      public void add(object object) {         em.persist(object);         // em.flush();  <---     } } 

it doesn’t work unless uncomment line thing don’t understand why need flush! shouldn’t transaction commit automatically?

could have ejb container , cdi transaction started observes never ends weird? or ends doesn’t commit because doesn’t know ejb?

persist() not meant insert row immediately, rather @ flush time, before transaction commit.

however, if not asking, row not inserted after transaction has ended, may flush mode transaction set manual.


Comments

Popular posts from this blog

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - JavaScript + Thymeleaf - select onchange -

node.js - Using Node without global install -