-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 3.6 + Spring 3.0.5 - The data not Recorded
PostPosted: Sat Dec 18, 2010 6:16 pm 
Newbie

Joined: Tue Dec 14, 2010 1:04 pm
Posts: 2
Hello,

I'm trying to use support for JPA of spring with hibernate but I have a problem: The data is not stored in the database, the strange thing is that the dependency injection occurs without problems and no exception occurs.

My spring's configuration is:

Code:
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
       
        <bean id="requestProcessAction" class="org.examples.action.RequestProcessAction" scope="prototype">
            <property name="procesoDAO" ref="daoProceso"/>
        </bean>

        <!--JPA with Spring and Hibernate -->
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

        <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

        <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">           
            <property name="dataSource" ref="dataSource"/>
            <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        </bean>

        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/database"/>
            <property name="username" value="user"/>
            <property name="password" value="pass"/>
        </bean>

        <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="MYSQL" />
            <property name="showSql" value="true" />
            <property name="generateDdl" value="false" />
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>

        <tx:annotation-driven transaction-manager="transactionManager" />

        <!-- DAOs -->
        <bean id="daoProceso" class="org.examples.daoImpl.ProcesoDAOHibernateJPA"/>
   
</beans>


My DAO example is:

Code:
package org.examples.daoImpl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.examples.dao.ProcesoDAO;
import org.examples.pojo.Proceso;
import org.springframework.stereotype.Repository;

@Repository
public class ProcesoDAOHibernateJPA implements ProcesoDAO{

    @PersistenceContext
    private EntityManager entityManager;

    public void addProceso(Proceso proceso) {
        System.out.println("Data: "+proceso.getNombre()+" "+proceso.getDescripcion());
        entityManager.persist(proceso);       
        System.out.println("Test Entity Manager: "+entityManager.toString());
    }
}


What could be the cause of this behavior? How I can fix it?

I hope someone can help me with this problem

Thanks in advance,


Top
 Profile  
 
 Post subject: Re: Hibernate 3.6 + Spring 3.0.5 - The data not Recorded
PostPosted: Sat Dec 18, 2010 7:09 pm 
Newbie

Joined: Fri Dec 17, 2010 1:22 pm
Posts: 5
you have to annotate your add* with transactional or use a aop pointcut


Top
 Profile  
 
 Post subject: Re: Hibernate 3.6 + Spring 3.0.5 - The data not Recorded
PostPosted: Mon Dec 20, 2010 12:03 pm 
Newbie

Joined: Tue Dec 14, 2010 1:04 pm
Posts: 2
Hello Negus, thanks for you answer,

I was doing some concept testing thinking in a version migration scenario. The strange thing is that the same configuration using earlier versions (Spring and Hibernate) works fine even when not using the annotation '@Transactional'.

I thought this would be an impediment to the migration of versions, but thanks to your response I see that there is no problem in using this combination of versions.

Thanks and regards,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.