2

大家好,你们知道 Hibernate 5.0.0.Final 发布了,我想将它集成到我的项目中,但是我的项目没有更新表并运行项目有一些问题。但它适用于 Spring 4.2 和 Hibernate 4.3.11 版本非常好.请帮我解决这个问题。

我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>tr.gov.diski</groupId>
    <artifactId>tender-project</artifactId>
    <packaging>war</packaging>
    <version>0.0.5-SNAPSHOT</version>
    <name>tender-project</name>

    <properties>
        <java.compiler.version>1.8</java.compiler.version>
        <maven-war-plugin.version>2.5</maven-war-plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <springframework-version>4.2.0.RELEASE</springframework-version>
        <spring-webflow-version>2.4.1.RELEASE</spring-webflow-version>
    </properties>

    <repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <!-- More info: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#overview-maven-bom -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>${springframework-version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-bom</artifactId>
                <version>3.2.5.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- JSF -->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.11</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>el-impl</artifactId>
            <version>2.2</version>
        </dependency>

        <!-- PrimeFaces -->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.2</version> 
        </dependency>


        <dependency>  
            <groupId>org.primefaces.themes</groupId>  
            <artifactId>all-themes</artifactId>  
            <version>1.0.10</version>  
        </dependency> 
        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>primefaces-extensions</artifactId>
            <version>3.2.0</version>
        </dependency>

        <!-- Spring Logging fix -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- Logging fix end -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
        </dependency>

        <!-- Spring webflow -->
        <!-- Needed for spring taglibs in facelets -->
        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-faces</artifactId>
            <version>${spring-webflow-version}</version>
        </dependency>

        <!-- Spring security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>
        <!-- For image upload -->
        <dependency>
            <groupId>org.imgscalr</groupId>
            <artifactId>imgscalr-lib</artifactId>
            <version>4.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>

        <!-- Hibernate dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-envers</artifactId>
            <version>5.0.0.Final</version>
        </dependency>


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.2.1.Final</version>
        </dependency>


        <!-- Connection pool -->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.1</version>
        </dependency>

        <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>5.0.0.Final</version>
</dependency>

        <!-- JSR-330 -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Test scope dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- APACHE COMMONS -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

    </dependencies>


    <build>
        <finalName>${artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${java.compiler.version}</source>
                    <target>${java.compiler.version}</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>${maven-war-plugin.version}</version>
                <configuration>
                    <outputDirectory>deployments</outputDirectory>
                    <warName>${artifactId}</warName>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

还有我的 applicationContext.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:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       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"
        >

    <import resource="security.xml"/>

    <context:component-scan base-package="tr.gov.diski.tender"/>
    <context:annotation-config/>
    <context:spring-configured/>
    <tx:annotation-driven/>

<!--     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> -->
<!--         <property name="driverClass" value="com.mysql.jdbc.Driver" /> -->
<!--         <property name="jdbcUrl" value="jdbc:mysql://localhost/deneme" /> -->
<!--         <property name="user" value="bilgeadam" /> -->
<!--         <property name="password" value="bilgeadam" /> -->
<!--         <property name="maxPoolSize" value="2" /> -->
<!--         <property name="maxStatements" value="0" /> -->
<!--         <property name="minPoolSize" value="1" /> -->
<!--     </bean> -->

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="oracle.jdbc.OracleDriver" />
        <property name="jdbcUrl" value="jdbc:oracle:thin:@192.168.10.16:1521:diskidb" />
        <property name="user" value="investment_tmp" />
        <property name="password" value="investment_tmp" />

        <property name="maxPoolSize" value="3" />
        <property name="maxStatements" value="0" />
        <property name="minPoolSize" value="1" />
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="tr.gov.diski.tender.model, tr.gov.diski.tender.common.audit" />
        <property name="hibernateProperties">
            <props>
<!--                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> -->
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.default_schema">INVESTMENT_TMP</prop>
                <prop key="org.hibernate.envers.audit_table_prefix">ZLOG_</prop>
                <prop key="org.hibernate.envers.audit_table_suffix"></prop>
                <prop key="org.hibernate.envers.store_data_at_delete">true</prop>
                <prop key="org.hibernate.envers.revision_on_collection_change">false</prop>
                <prop key="org.hibernate.envers.do_not_audit_optimistic_locking_field">false</prop>
                <prop key="hibernate.default_batch_fetch_size">16</prop>
                <prop key="hibernate.enable_lazy_load_no_trans">true</prop>

            </props>
        </property>

        <!-- Envers - Auditlogging -->
<!--        <property name="eventListeners"> -->
<!--            <map> -->
<!--                <entry key="post-insert"><ref local="enversListener" /></entry> -->
<!--                <entry key="post-update"><ref local="enversListener" /></entry> -->
<!--                <entry key="post-delete"><ref local="enversListener" /></entry> -->
<!--                <entry key="pre-collection-update"><ref local="enversListener" /></entry> -->
<!--                <entry key="pre-collection-remove"><ref local="enversListener" /></entry> -->
<!--                <entry key="post-collection-recreate"><ref local="enversListener" /></entry> -->
<!--            </map> -->
<!--        </property> -->
    </bean>

<!--     <bean id="enversListener" class="org.hibernate.envers.event.AuditEventListener" /> -->

    <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>


                <!--And here is the rememberMeServices bean: -->
                <!-- Defines which remember me implementation to use - in this case using a database table to log 'remembered' tokens -->

                 <bean class="org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices"   id="rememberMeServices"> 
                <property name="tokenRepository" ref="jdbcTokenRepository"></property>
                <property name="userDetailsService" ref="customUserDetailsService"></property>
                <property name="tokenValiditySeconds" value="864000"></property>
                <property name="cookieName" value="SPRING_RM"></property>
                <property name="key" value="myAppKey"></property>
                <property name="alwaysRemember" value="true"/>
            </bean>


            <bean class="org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl" id="jdbcTokenRepository">
                <property name="createTableOnStartup" value="false"></property>
                <property name="dataSource" ref="dataSource"></property>
            </bean>

            <!-- Remember-Me authentication provider declared here -->
            <bean class="org.springframework.security.authentication.RememberMeAuthenticationProvider" id="rememberMeAuthenticationProvider">
              <!-- This ensures that remember-me is added as an authentication provider -->
              <property name="key" value="myAppKey"></property>
            </bean>
            <!-- we need is to define a Remember-Me filter that should intercept HTTP requests and validate cookies whenever needed:  -->
            <bean class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter" id="rememberMeFilter">
                 <property name="rememberMeServices" ref="rememberMeServices"></property>
                 <property name="authenticationManager" ref="authenticationManager"></property>
            </bean>


</beans>
4

0 回答 0