Announcement Announcement Module
Collapse
No announcement yet.
Requires_new rollback when outer transaction fails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Requires_new rollback when outer transaction fails

    hi,
    i m new to spring, and i faced this weird probleme,

    my source code is as follow:

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void persisteRelationShip(int idp, int idv) {
    Personne p = new Personne();
    p.setIdpersonne(idp);
    p.setLogin("p2");
    p.setPasswd("p2");
    personneDao.merge(p);
    Velo v = new Velo();
    v.setIdvelo(idv);
    v.setNomVelo("VTT");
    v.setPersonne(p);
    veloDao.merge(v);
    }

    @Transactional
    public void removeWithRelationShip(int idp, int idv) {
    persisteRelationShip(idp, idv);
    Personne p=personneDao.findById(idp);
    p.setLogin("jaaaaaaaaaaao");
    throw new RuntimeException();
    }



    I ve thrown intentionally an exception in the second method to prompt a rollback.

    in a main when i call the second method (removeWithRelationShip), an exception is generated as expected, but surprisingly i don't find my person and velo in the database, isn't that normal.??? or it's me who didn't understand the "requires_new" propagation type. thank you in advance

    NB: i use an eclipselink implementation for JPA, a LocalContainerEntityManagerFactoryBean with pooled datasource (dbcp), and a simple JPAtransactionManager, the underlying database is a Mysql DB.
    Last edited by xcoffin; Apr 4th, 2011, 05:11 PM.

  • #2
    i m so upset that noone's take the pain to put some tracks that i can follow, but any way i love U all ,
    thanks to the open source, i could debug and figure out that i must call the method from a bean reference picked from the spring context to allow him(spring) to put his transactional stuff via proxing.

    conclusion :don't call your methods directly to benifits from AOP in general (i think with compile time weaving that will work anyway).

    Comment

    Working...
    X