jpa相关知识总结

1)jpa 需要在classpath中存在jpa实现jar才行,比如hibernate-entitymanager.jar,下面有META-INF\services javax.per...文件中配置了jpa实现
org.hibernate.ejb.HibernatePersistence

当classpath下没有jpa实现jar是不会启动jpa的。

2)jpa会找classpath所有的META-INF/persistence.xml文件,如果有多个包含persistence.xml文件的jar可能会产生冲突,所以要避免classpath下同时存在多个包含persistence.xml文件的jar

3)为了实现将实体放入不同的jar中,jpa提供了jar-file和class方式,jar-file按文件路径加载,../。。jar表示与META-INF同级下的jar。通过<jar-file>方式引入的jar也会加入到classpath中,所以要避免这些jar中包含persistence.xml文件,可以通过maven的prifile动态决定是否将persistence.xml文件打入jar中。

<persistence-unit name="bspGroup1">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/bspGroup1DataSourceSMP</jta-data-source>
        <jar-file>../isss-domainmodel-1.0.0-SNAPSHOT.jar</jar-file>

        <jar-file>../isss-domainmodel-222.jar</jar-file>
        <class>sample.EntityA</class>

        <class>sample.EntityB</class>

        <properties>。。。。。。。。。

4)数据源配置文件(xxxds.xml)可以放在包含persistence.xml文件的jar里面,与META-INF平级,不用非要放在jboss的deploy目录下面,但要保证各ear下的ds不会重复,因为他们都要去同一jndi中注册。

猜你喜欢

转载自yourenyouyu2008.iteye.com/blog/1329681