forked from Impetus/kundera
-
Notifications
You must be signed in to change notification settings - Fork 0
Elasticsearch as a data store
Devender Yadav edited this page Sep 14, 2016
·
4 revisions
Being a JPA provider, Kundera provides support for Elasticseach.
Kundera Elasticsearch mapping -
JPA attribute | Elasticsearch attribute |
---|---|
Schema Name | Index Name |
Table Name | Index Type |
Primary Key | Index Id |
##Persistence unit configuration
<persistence-unit name="es-pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9300" />
<property name="kundera.keyspace" value="esSchema" />
<property name="kundera.dialect" value="es" />
<property name="kundera.client.lookup.class" value="com.impetus.client.es.ESClientFactory" />
</properties>
</persistence-unit>
##Example
###Entity
@Entity
@Table(name = "BOOK", schema = "esSchema@es-pu")
public class Book
{
@Id
@Column(name = "BOOK_ID")
private int bookId;
@Column(name = "TITLE")
private String title;
@Column(name = "AUTHOR")
private String author;
@Column(name = "NUM_PAGES")
private int numPages;
// getters and setters
}
###Testcase
EntityManagerFactory emf = Persistence.createEntityManagerFactory("es-pu");
EntityManager em = emf.createEntityManager();
Book b = new Book();
b.setBookId(101);
b.setAuthor("George R. R. Martin");
b.setTitle("A Game of Thrones");
b.setNumPages(694);
em.persist(b);
This book object in persisted in Elasticsearch under esSchema
schema, BOOK
index with 101 id.