我们在同一个项目中存在多个持久性单元的问题。我们需要在同一时间使用两个持久性单元。一个用Hibernate for MySQL的“正常”,另一个用Kundera for Cassandra。具有各种JPA版本的复合持久性单元
问题是,与Hibernate/MySQL不同,Kundera/Cassandra似乎不支持JPA 2.1。
持久XML看起来像:
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="pu-mysql" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/datasrc</jta-data-source>
<class>com.blah.Contact</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
<persistence-unit name="cassandra-pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<class>com.blah.nosql.PostLogNosql</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="kundera.nodes" value="localhost"/>
<property name="kundera.port" value="9042"/>
<property name="kundera.keyspace" value="keyspace_name"/>
<property name="kundera.dialect" value="cassandra"/>
<property name="kundera.ddl.auto.prepare" value="validate"/>
<property name="kundera.client.lookup.class" value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory"/>
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
<property name="kundera.annotations.scan.package" value="com.blah.nosql"/>
<property name="jboss.as.jpa.managed" value="false"/>
</properties>
</persistence-unit>
</persistence>
这没有奏效。由于昆德拉不支持JPA 2.1,系统没有看到昆德拉文件的一部分。我们得到org.hibernate.HibernateException:Missing column:time_key in keyspace_name.ourtable error。
这是通过将持久性标题更改为版本2.0解决的。标题然后看起来如下:
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_0.xsd">
...一切都像一个魅力。到现在为止还挺好。
现在,问题是什么发生在Hibernate/MySQL作为JPA 2.1兼容。是否仍然可以使用所有JPA 2.1特定功能,还是仅限于与JPA 2.0相关的子集?
如果是后者,我怎么能在同一时间使用Hibernate/MySQL作为JPA 2.1和Kundera/Cassandra作为JPA 2.0?
使用的应用服务器是Wildfly 8和Wildfly 9.非常感谢。
你在CLASSPATH中有一个JPA API jar,所以会出现任何问题。如果您尝试使用JPA 2.0,那么您可能会使用Hibernate获取AbstractMethodError等,反之亦然,使用JPA 2.1和Kundera。你可以选择像DataNucleus和Cassandra一样使用JPA 2.1(也可以使用RDBMS FWIW)。 persistence.xml头是你的问题最少... 2.0是足够的,因为在JPA 2.1 –
没有任何变化你好@尼尔斯托克顿,谢谢你,这应该是一个有效的答案。我们终于在别处解决了这个问题,但是,您的解释是有价值的。 – TomS
@TomS我不认为这个问题是因为“Kundera不支持JPA 2.1”,因为我试图使用Kundera与持久性头版本2.1,它的工作原理!另外,你能分享你的问题如何解决? –