Skip to content

No Hard Annotation for Schema Required

chhavigangwal edited this page Oct 18, 2013 · 15 revisions

Use same class for persisting data over multiple data stores in different schema using Kundera now ! In our latest release we have removed the compulsion of binding an entity with hard annotation for schema and its pu.

A typical Entity class in Kundera :

@Entity
@Table(name = "KunderaUser", schema = "KunderaMetaDataTest@metaDataTest")
public class KunderaUser
{

    @Id
    @Column(name = "USER_ID")
    private String userId;

Mentioned below are the ways in which you can create Entity classes and use with Kundera now.

Entity without @Table annotation :

As per JPA specifications , the default persistence unit and schema name are picked from persistence unit for which the EntityManagerFactory have been instantiated in case when no table annotation is given. The table name is same as entity class name.

@Entity
public class PersonDetail
{
    /** The person id. */
    @Id
    private String personId;

    /** The first name. */
    @Column(name = "first_name")
    private String firstName;

This class can also be mapped in multiple persistence-unit and its schema name is picked from PU definition.

<persistence-unit name="noAnnotationAddMongo">
		<provider>com.impetus.kundera.KunderaPersistence</provider>
		<class>com.impetus.kundera.tests.entities.PersonDetail</class>
		....
	</persistence-unit>

Entity with @Table annotation/without schema:

As per JPA specifications , the default persistence unit and schema name in this case will be picked from persistence unit for which the EntityManagerFactory have been instantiated. The table name will be the one given in @table Annotation.

@Entity
@Table(name = "person")
public class PersonDetail
{
    
    /** The person id. */
    @Id
    private String personId;

    /** The first name. */
    @Column(name = "first_name")
    private String firstName;

    /** The last name. */
    @Column(name = "last_name")
    private String lastName;

Home

Clone this wiki locally