Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JPA Layer Over Kudu Using Kundera (Part 2)

DZone's Guide to

JPA Layer Over Kudu Using Kundera (Part 2)

Learn about the new features of Kundera with Kudu, such as support for embedded entities, secondary indexes, and positional and parameterized queries.

· Database Zone
Free Resource

Traditional relational databases weren’t designed for today’s customers. Learn about the world’s first NoSQL Engagement Database purpose-built for the new era of customer experience.

Before getting started, be sure to check out Part 1

New Features of Kundera-Kudu

These features are available from Kundera 3.9 onwards.

Embedded Entities Are Supported

Embedded entities are stored in parallel to columns (similar to RDBMS).

Entity:

@Entity
@Table(name = "PERSON_EMBED_KUDU", schema = "keyspace-Name@pu-name")
public class EmbeddablePerson {
 @Id
 private String personId;

 private String personName;

 @Embedded
 private Address address;

}

Embedded entity:

@Embeddable
public class Address {
 private String street;

 private String city;

 private String country;
}

For more details, refer to this GitHub page on embeddables support in Kudu.

Primary Key Auto Generation

Currently, GenerationType.AUTO is supported.

@Entity
@Table(name = "USER", schema = "keyspace-Name@pu-name")
public class User {
 @Id
 @GeneratedValue(strategy = GenerationType.AUTO)
 private String id;

 @Column
 private String name;

 // getter and setter
}

The id attribute in the entity must be of String type.

Secondary Indexes Using Elasticsearch

Elasticsearch can be used to store indexes of Kudu to perform faster aggregations. Refer to this GitHub page on Elasticsearch as an Index store for more details.

Positional and Parameterized Query Support

Sample queries:

  Query query = em.createQuery("Select p.age, p.salary from Person p where p.age >= ?1 and p.age <= ?2");
  query.setParameter(1, 20);
  query.setParameter(2, 40);
  List < Person > results = query.getResultList();

  Query query = em.createQuery("Select p.age, p.salary from Person p where p.age >= :age1 and p.age <= :age2");
  query.setParameter("age1", 20);
  query.setParameter("age2", 40);
  List < Person > results = query.getResultList();

Conclusion

Kundera, being JPA compliant, makes it easier to work with NoSQL databases. Regardless of the database used, the user needs to write the same JPA query. Also, if a user wants to switch databases (say from HBase to Kudu), there is no need to rewrite the code — just change some configurations in the persistence.xml file.

Learn how the world’s first NoSQL Engagement Database delivers unparalleled performance at any scale for customer experience innovation that never ends.

Topics:
kundera ,kudu ,database ,jpa

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}