kundera-cassandra 在使用 spring 时在 EntityManagerFactory 上设置 cql 版本

kundera-cassandra set cql version on EntityManagerFactory when using spring

我想在 kundera-cassandra (V3.2) 实体中使用序列生成器。参考这个 https://github.com/impetus-opensource/Kundera/issues/777 我必须在创建 EntityManagerFactory 时将 CQL 版本设置为版本 3,而不是在创建 EntityManager 时。我的问题是我使用 Spring 并且在自动装配 EntityManagerFactory.

时我不知道如何设置 属性
@Id
@TableGenerator(name = "id_gen", allocationSize = 30, initialValue = 100)
@GeneratedValue(generator = "id_gen", strategy = GenerationType.TABLE)
private String id;

在我的存储库中,我这样定义 EntityManagerFactory

@PersistenceUnit
private EntityManagerFactory entityManagerFactory;

在我的应用程序中-context.xml 我这样定义 Bean:

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="cassandra_pu" />
</bean> 

<bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
    <property name="persistenceXmlLocations">
        <list>
            <value>classpath:persistence.xml</value>
        </list>
    </property>
</bean>

谁能告诉我在哪里设置版本-属性?

您可以执行以下操作:

  • 创建一个 xml 文件说 cass-props.xml 并添加以下内容:

<?xml version="1.0" encoding="UTF-8"?> <clientProperties> <datastores> <dataStore> <name>cassandra</name> <connection> <properties> <property name="cql.version" value="3.0.0" /> </properties> <servers> <server> <host> localhost </host> <port> 9160 </port> </server> </servers> </connection> </dataStore> </datastores> </clientProperties>

  • 然后在你的persistence.xml

    中添加下面的属性

    <property name="kundera.client.property" value="cass-props.xml" />