我想在 kundera-cassandra (V3.2) 实体中使用序列生成器。引用这个https://github.com/impetus-opensource/Kundera/issues/777我必须在创建 EntityManagerFactory 时(而不是创建 EntityManager 时)将 CQL 版本设置为版本 3。我的问题是我使用 Spring 并且我不知道在 Autowiring 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;
在我的 application-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" />
关于java - kundera-cassandra 使用 spring 时在 EntityManagerFactory 上设置 cql 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34354063/