【问题标题】:SessionFactory can't be got after compiling to jar by mavenmaven编译成jar后无法获取SessionFactory
【发布时间】:2016-03-15 16:47:03
【问题描述】:

我使用的是与Spring集成的Hibernate,请在下面找到SessionFactory的bean,在Eclipse中一切正常,但是编译为jar(mvn install)后无法获取sessionFactory,我的意思是会话从 sessionFactory 获得的将为空。

<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>

*.hbm.xml文件在src/main/resources,编译后查看了classpath,一无所获。

有人可以帮忙提供任何建议吗?

谢谢。

【问题讨论】:

  • 能否附上错误日志。
  • 类和附加配置。什么是空?你也没有hibernate.cfg.xmlhibernate.properties 某处/
  • @HarbeerKadian 错误是NullPointerException 由从会话工厂获取的空会话引起的,实际上根本原因是sessionFactory bean初始化失败。
  • @M.Deinum Hibernate我用的是spring集成的,所以没有hibernate.cfg.xml和hibernate.properties。
  • 谢谢大家,我现在解决这个问题。

标签: java spring hibernate maven sessionfactory


【解决方案1】:

我发现我的类路径中有两个不同版本的 hibernate-commons-annotations jar。

/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

在 Eclipse 中触发的运行中,hibernate-commons-annotations-5.0.0.Final.jar 工作正常,我得到了日志

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

但是,在shell脚本触发的运行中,选择了hibernate-commons-annotations-3.5.6.Final.jar,系统失败。而日志就像

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2017-12-22
    • 2012-04-13
    • 2012-05-03
    • 2020-09-06
    • 2021-05-31
    • 1970-01-01
    相关资源
    最近更新 更多