Hi,
Is it possible to increment PK using kunderaCounter.xml in kundera2.8?
Is it possible to make (PK) column type only as COUNTER in CF using kunderaCounter.xml?
When I place my entity in kunderaCounter.xml, all my columns in CF will be marked as COUNTER.
-------------------------------------------------------------------------------------------------------------------
Employee entity
-----------------
@Entity
@Table(name = "employee")
@IndexCollection(columns = { @Index(name = "EMPLOYEE_NAME"),
@Index(name = "DESIGNATION"), @Index(name = "EXPERIENCE"),
@Index(name = "PROJECT") })
@NamedQueries({
@NamedQuery(name = "retrieveEmployee", query = "select e from Employee e where e.employeeName = ?1"),
@NamedQuery(name = "findEmployeeById", query = "select e from Employee e where e.employeeId = ?1") })
public class Employee {
@Id
@Column(name = "employee_id")
@GeneratedValue(strategy = GenerationType.TABLE)
private int employeeId;
@Column(name = "employee_name")
private String employeeName;
@Column(name = "experience")
private int experience;
@Column(name = "designation")
private String designation;
@Column(name = "project")
private String currentProject;
.
.
//getter setter
.
}
Department entity
-----------------
@Entity
@Table(name = "department")
@IndexCollection(columns = { @Index(name = "dept_name"),
@Index(name = "dept_code") })
@NamedQueries({
@NamedQuery(name = "retrieveDepartment", query = "select d from Department d where d.deptName = ?1"),
@NamedQuery(name = "findDeptById", query = "select d from Department d where d.deptId = ?1") })
public class Department {
@Id
@Column(name = "dept_id")
@GeneratedValue(strategy = GenerationType.TABLE)
private int deptId;
@Column(name = "dept_name")
private String deptName;
@Column(name = "dept_code")
private String deptCode;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "deptId")
private List<Employee> employeeList;
.
.
//getter setter
.
}
-------------------------------------------------------------------------------------------------------------------
MY TC
Department d = new Department();
d.setDeptCode("101");
// d.setDeptId(UUID.randomUUID().toString());
d.setDeptName("eComm");
Employee e1 = new Employee();
e1.setCurrentProject("Proj1");
e1.setDesignation("AST1");
// e1.setEmployeeId(UUID.randomUUID().toString());
e1.setEmployeeName("Subash1");
e1.setExperience(1);
Employee e2 = new Employee();
e2.setCurrentProject("Proj2");
e2.setDesignation("AST2");
// e2.setEmployeeId(UUID.randomUUID().toString());
e2.setEmployeeName("Subash2");
e2.setExperience(2);
Employee e3 = new Employee();
e3.setCurrentProject("Proj3");
e3.setDesignation("AST3");
// e3.setEmployeeId(UUID.randomUUID().toString());
e3.setEmployeeName("Subash3");
e3.setExperience(2);
Employee e4 = new Employee();
e4.setCurrentProject("Proj4");
e4.setDesignation("AST4");
// e4.setEmployeeId(UUID.randomUUID().toString());
e4.setEmployeeName("Subash4");
e4.setExperience(2);
List<Employee> el = new ArrayList<Employee>();
el.add(e1);
el.add(e2);
el.add(e3);
el.add(e4);
d.setEmployeeList(el);
em.persist(d);
-------------------------------------------------------------------------------------------------------------------
after test run, kundera_sequences output is
cqlsh:jan10> select * from kundera_sequences;
key | sequence_value
------------+----------------
department | 1
employee | 4
(2 rows)
-------------------------------------------------------------------------------------------------------------------
PU
<persistence-unit name="cassandra-pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<class>com.impetus.kundera.entities.Department</class>
<class>com.impetus.kundera.entities.Employee</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="jboss.as.jpa.managed" value="false" />
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9160" />
<property name="kundera.keyspace" value="jan10" />
<property name="kundera.dialect" value="cassandra" />
<property name="kundera.ddl.auto.prepare" value="create" />
<property name="kundera.client" value="thrift" />
<property name="kundera.client.lookup.class"
value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
<property name="kundera.cache.provider.class"
value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
<property name="kundera.client.property" value="kunderaCounter.xml" />
</properties>
</persistence-unit>
-------------------------------------------------------------------------------------------------------------------
kunderaCounter.xml is
<?xml version="1.0" encoding="UTF-8"?>
<clientProperties>
<datastores>
<dataStore>
<name>cassandra</name>
<schemas>
<schema>
<name>jan10</name>
<tables>
<table>
<name>department</name>
<properties>
<property name="default.validation.class" value="CounterColumnType"></property>
<property name="key.validation.class" value="UTF8Type"></property>
</properties>
</table>
<table>
<name>employee</name>
<properties>
<property name="default.validation.class" value="CounterColumnType"></property>
<property name="key.validation.class" value="UTF8Type"></property>
</properties>
</table>
</tables>
</schema>
</schemas>
</dataStore>
</datastores>
</clientProperties>
-------------------------------------------------------------------------------------------------------------------
Trace
WARNING: Counter value not found for sequence_name, resetting it to zero.
Jan 14, 2014 3:37:06 PM com.impetus.client.cassandra.CassandraClientBase createUpdateQueryForCounter
INFO: Returning update query UPDATE "department" SET "dept_name"="dept_name"+'eComm', "dept_code"="dept_code"+'101' WHERE "key"=1.
Jan 14, 2014 3:37:06 PM com.impetus.client.cassandra.thrift.ThriftClient onPersist
SEVERE: Error while persisting record, Caused by: .
InvalidRequestException(why:Invalid STRING constant (eComm) for dept_name of type counter)
at org.apache.cassandra.thrift.Cassandra$execute_cql3_query_result.read(Cassandra.java:37849)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_execute_cql3_query(Cassandra.java:1562)
at org.apache.cassandra.thrift.Cassandra$Client.execute_cql3_query(Cassandra.java:1547)
at com.impetus.client.cassandra.CassandraClientBase$CQLClient.persist(CassandraClientBase.java:1865)
at com.impetus.client.cassandra.thrift.ThriftClient.onPersist(ThriftClient.java:150)
at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:88)
at com.impetus.client.cassandra.thrift.ThriftClient.persist(ThriftClient.java:132)
at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:183)
at com.impetus.kundera.graph.Node.flush(Node.java:533)
at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:413)
at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:151)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:168)
at com.impetus.kundera.dao.PersistenceDAO.insertEmployeeAndDept(PersistenceDAO.java:156)
at com.impetus.kundera.dao.PersistenceDAO.main(PersistenceDAO.java:239)
Exception in thread "main" com.impetus.kundera.KunderaException: com.impetus.kundera.KunderaException: InvalidRequestException(why:Invalid STRING constant (eComm) for dept_name of type counter)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:174)
at com.impetus.kundera.dao.PersistenceDAO.insertEmployeeAndDept(PersistenceDAO.java:156)
at com.impetus.kundera.dao.PersistenceDAO.main(PersistenceDAO.java:239)
Caused by: com.impetus.kundera.KunderaException: InvalidRequestException(why:Invalid STRING constant (eComm) for dept_name of type counter)
at com.impetus.client.cassandra.thrift.ThriftClient.onPersist(ThriftClient.java:168)
at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:88)
at com.impetus.client.cassandra.thrift.ThriftClient.persist(ThriftClient.java:132)
at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:183)
at com.impetus.kundera.graph.Node.flush(Node.java:533)
at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:413)
at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:151)
at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:168)
... 2 more
Caused by: InvalidRequestException(why:Invalid STRING constant (eComm) for dept_name of type counter)
at org.apache.cassandra.thrift.Cassandra$execute_cql3_query_result.read(Cassandra.java:37849)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_execute_cql3_query(Cassandra.java:1562)
at org.apache.cassandra.thrift.Cassandra$Client.execute_cql3_query(Cassandra.java:1547)
at com.impetus.client.cassandra.CassandraClientBase$CQLClient.persist(CassandraClientBase.java:1865)
at com.impetus.client.cassandra.thrift.ThriftClient.onPersist(ThriftClient.java:150)
... 9 more
-------------------------------------------------------------------------------------------------------------------
Thanks