Note that there are some explanatory texts on larger screens.

plurals
  1. POData does not persist using HIbernate with Spring's @Transactional Annotation
    primarykey
    data
    text
    <p>I have an application that I am currently writing that will use Spring and Hibernate. In my services layer I have injected a DAO that will do some very basic CRUD-ing actions. For grins, I have created a method annotated as follows:</p> <pre><code>@Transactional(readOnly = false, propogation=Propogation.REQUIRES_NEW) public void doSomeWork(Dao dao, Entity e){ //do some searching dao.persist(e); dao.findAll(Entity.clz); } </code></pre> <p>The dao persist method looks like this:</p> <pre><code>public void persist(Entity e){ session.saveOrUpdate(e); //This has already been built using a SessionFactory } </code></pre> <p>The dao findAll method looks like this</p> <pre><code>public void findAll(Class clz) { session.createCriteria(clz).list(); } </code></pre> <p>Now, everything seems to run, OK. After I insert (persist) my object, I can see it using the findAll method (along with the new Primary Key ID that it was assigned by the Data Store), however, when the "doSomeWork" method completes, my data does not actually get persisted to the underlying datastore (Oracle 10g). </p> <p>If, however, I remove the @Transactional annotations and use Hibernate's session.getTransaction().begin() and session.getTransaction().commit() (or rollback), the code works as I would anticipate. </p> <p>So, my underlying question would then be: Does Hibernate not actually use Spring's transaction management for actual transaction management? </p> <p>In my bean-config file I am declaring a TransactionManager bean, a SessionFactory bean, and I am also including in the config file. </p> <p>What could I possibly be missing, aside for a better working-knowledge of Spring and Hibernate?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload