java - JPA - Container Managed Persistence doesn't persist entity -JTA -


i m trying integrate spring , jsf stuck on persisting object. dont want handle transaction (begin - commit etc)

after googling find answer give need in link

i'm using eclipselink orm , oracle 11g database , glassfish server 3.1 maven. prefered annotation spring configuration. use

@transactional @service 

annotations in related class. persistence.xml name e_deftermanagementpu , transaction-type jta. here code persist efafunctions

public entitymanager entitymanager;  @inject public void setentitymanager() {     entitymanagerfactory emf = persistence.             createentitymanagerfactory("e_deftermanagementpu");     this.entitymanager = emf.createentitymanager(); }      public void create(efafunctions efafunctions) {                   entitymanager.persist(efafunctions);   } 

entity manager not null , can see **assign sequence object ** log on glassfish other logs not generated if write code below whic invisible parts same aboe code block ;

public void create(efafunctions efafunctions) {            entitymanager.gettransaction().begin();     entitymanager.persist(efafunctions);       entitymanager.gettransaction().commit(); } 

it persists object. works dont want handle begin() commit() parts , according resources jta container managed persistence should instead of me. can body tell me m wrong in advance

in jsf managed beans there no implicit transactions. way avoid managing transactions manually create ejb in application server, , have jsf managed bean call persist data. using glassfish, using ejb possible... new level of complexity. great way handle persistence transactions have try-catch block template this:

    entitymanager em = ... //however em.     try {         em.gettransaction().begin();          // ...  put persistence code here.          em.gettransaction().commit();     } catch (exception ex) {         em.gettransaction().rollback();         throw ex;     }finally {         em.close();     } 

it not clean looking super slick cdi , automatic transactions, handle transactions properly, , ensure data integrity.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -