2

这些天我正在使用JPA(Hibernate)和spring项目,我配置了spring,jpa并尝试在tomcat7上部署应用程序,据我所知jpa / hibernate使用实体类首先加载创建表,但在这里我看不到应用程序启动时数据库和应用程序之间的任何连接,下面你可以看到我的配置,我已经看到很多关于这个问题的问题,我找不到我的问题的正确解决方案。

谁能告诉我这里有什么问题。我在码头服务器上创建了一个没有任何问题的应用程序,提前谢谢你

applicationContext-dao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-3.0.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
       default-lazy-init="true">

    <!-- Use @Transaction annotations for managing transactions  -->
    <!--<tx:annotation-driven/>-->

    <!-- holding properties for database connectivity / -->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <tx:annotation-driven proxy-target-class="true" />
    <!-- Activates scanning of @Autowired -->
    <context:annotation-config/>

    <!-- Activates scanning of @Repository -->
    <context:component-scan base-package="lk.gov.elg"/>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

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

    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"
          p:driverClassName="${jdbc.driverClassName}"
          p:url="${jdbc.url}"
          p:username="${jdbc.username}"
          p:password="${jdbc.password}"/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
          p:entityManagerFactory-ref="entityManagerFactory"
          p:dataSource-ref="dataSource"/>

    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:dataSource-ref="dataSource"
          p:jpaVendorAdapter-ref="jpaAdapter">
        <property name="persistenceUnitName" value="eLGPersistenceUnit"></property>
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
        </property>
    </bean>

    <!-- Jpa adapter for the Hibernate -->
    <bean id="jpaAdapter"
          class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
          p:databasePlatform="org.hibernate.dialect.MySQLDialect"
          p:generateDdl="true"
          p:showSql="true"  >
    </bean>

    <bean
            class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>

    <bean
            class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
</beans>

持久性.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
             xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="eLGPersistenceUnit"
                      transaction-type="RESOURCE_LOCAL">
    <!--transaction-type="JTA">-->
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="validate"/>
        </properties>
        <!--<provider>org.hibernate.ejb.HibernatePersistence</provider>-->
    </persistence-unit>
</persistence>
4

2 回答 2

1

我认为您的配置没有问题,请在删除“default-lazy-init=true”属性后尝试

干杯

于 2012-09-06T21:46:57.410 回答
0

尝试改变:

<property name="hibernate.hbm2ddl.auto" value="validate"/>

到:

<property name="hibernate.hbm2ddl.auto" value="update"/>

或者:

<property name="hibernate.hbm2ddl.auto" value="create"/>
于 2012-09-06T21:53:57.597 回答