简体   繁体   中英

SessionFactory can't be got after compiling to jar by maven

I'm using Hibernate integrated with Spring, please find bean for SessionFactory as below, all works well in Eclipse, however, sessionFactory can't be got after compiling to jar ( mvn install ), I mean the session got from the sessionFactory would be null.

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSourceOri" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.EHCacheProvider</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
            <prop key="hibernate.jdbc.batch_size">1024</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.enable_lazy_load_no_trans">true</prop>
            <prop key="hibernate.jdbc.batch_size">50</prop>
            <prop key="hibernate.order_inserts">true</prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>ClassA.hbm.xml</value>
            <value>ClassB.hbm.xml</value>
            <value>ClassC.hbm.xml</value>
        </list>
    </property>
</bean>

The *.hbm.xml files are in src/main/resources , and I checked the classpath after the compiling and found nothing.

Could anyone help to give any advice about it ?

Thanks.

I found there are two hibernate-commons-annotations jars with different version in my classpath.

/Users/name/aa-o/target/aa-o-0.0.1-SNAPSHOT/doctor-o-0.0.1-SNAPSHOT/lib/hibernate-commons-annotations-5.0.0.Final.jar:/Users/name/aa-o/target/aa-o-0.0.1-SNAPSHOT/lib/hibernate-commons-annotations-3.5.6.Final.jar

In the running triggered in Eclipse, hibernate-commons-annotations-5.0.0.Final.jar works and all's well, I get the log

INFO [qtp1412752396-16] org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.0.Final}

However, in the running triggered by shell script, hibernate-commons-annotations-3.5.6.Final.jar is chosen and system failed. And log is like

INFO [qtp1412752396-16] org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {3.5.6.Final}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM