使用hibernate和spring不会将数据存储在数据库中

时间:2015-11-17 23:38:49

标签: spring hibernate jpa

我尝试在数据库中添加元素,当我运行什么都没有存储时,我正在使用hibernate和spring来开发与mavan的web应用程序。我没有任何错误,但没有存储任何内容 的applicationContext.xml

    <bean id="datasource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    <property name="url" value="jdbc:mysql://localhost:3306/gestion_bp"></property>
    <property name="username" value="root"></property>
    <property name="password" value=""></property>
</bean>
<bean id="persistenceUnitManager"
    class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="defaultDataSource" ref="datasource"></property>
    <property name="persistenceXmlLocations">
        <list>
            <value>classpath*:META-INF/hibernate.cfg.xml</value>
        </list>
    </property>
</bean>
<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitManager" ref="persistenceUnitManager"></property>
    <property name="persistenceUnitName" value="GESTION_BP"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"></property>
</bean>
<bean id="dao" class="com.sqli.bap.daoImpl.PersonneDaoImpl"></bean>
<bean id="metier" class="com.sqli.bap.metierImpl.PersonneMetierImpl">
    <property name="dao" ref="dao"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<context:annotation-config></context:annotation-config>

hibernate.xml文件

    <persistence-unit name="GESTION_BP"
    transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
    </properties>
</persistence-unit>

这些是我的道教课程

public class PersonneDaoImpl implements IPersonneDao {
@PersistenceContext
private EntityManager em;

@Override
@Transactional
public void ajouterPersonne(Personne personne) {
    //em.getTransaction().begin();
    em.persist(personne);
    //em.getTransaction().commit();
}

0 个答案:

没有答案