Impetus / kundera

A JPA 2.1 compliant Polyglot Object-Datastore Mapping Library for NoSQL Datastores.Please subscribe to:
http://groups.google.com/group/kundera-discuss/subscribe
Apache License 2.0
903 stars 233 forks source link

Data getting persisted to the different persisting unit. #459

Closed shiva404 closed 10 years ago

shiva404 commented 10 years ago

If I have two persisting units, lets say cassandra_pu and mysql_pu. And my persister.xml looks

`

com.impetus.kundera.KunderaPersistence com.intuit.test.internal.types.Person
<persistence-unit name="cassandra_pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
    <class>com.intuit.test.internal.types.Address</class>
    <properties>
    <property name="kundera.nodes" value="localhost"/>
    <property name="kundera.port" value="9160"/>
    <property name="kundera.keyspace" value="kunderaexamples"/>
    <property name="kundera.dialect" value="cassandra"/>
    <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
    <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.ddl.auto.prepare" value="update" />
</properties>

`

and my entity definition looks below.

@Entity @Table(name="person") public class Person {

@Embedded PersonalData personalData;

But data goes to the cassandra_pu rather than mysql_pu. But if I specify scheme it goes to the mysql_pu.

@Table(name="person", schema="test")

Can you please take a look. Is it mandatory to specify the schema for RDBMS entities?

shiva404 commented 10 years ago

I am sorry.. XML data markdown is not working

mevivs commented 10 years ago

Could you please enclose XML and entity definitions within "```" as below ?

-Vivek

mevivs commented 10 years ago

Looks like some issue <class> tags are not mapped correctly.

Here i am sharing an example to implement polyglot persistence without using schema.

Person.java (goes into RDBMS)

@Entity
@Table(name = "PERSON")
public class Person
{
    @Id
    @Column(name = "PERSON_ID")
    private String personId;

    @Column(name = "PERSON_NAME")
    private String personName;

    @Embedded
    PersonalData personalData;

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "ADDRESS_ID")
    private Address address;

    public Person()
    {

    }

// setters and getters here.

Address.java ( Goes into Cassandra)

@Entity
@Table(name = "ADDRESS")
public class Address
{
    @Id
    @Column(name = "ADDRESS_ID")
    private String addressId;

    @Column(name = "STREET")
    private String street;

    public Address()
    {

    }

// setters and getters here.

PersonalData.java (Embeddable entity)


@Embeddable
public class PersonalData
{
    @Column(name = "p_website")
    private String website;

    @Column(name = "p_email")
    private String email;

    @Column(name = "p_yahoo_id")
    private String yahooId;

    public PersonalData()
    {

    }

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
    <persistence-unit name="mysqlPU">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <class>com.example.kundera.Person</class>
        <!-- <class>com.example.kundera.Address</class> -->
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="kundera.client.lookup.class" value="com.impetus.client.rdbms.RDBMSClientFactory" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test" />
            <property name="hibernate.connection.username" value="root" />
            <property name="hibernate.connection.password" value="root" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
            <property name="hibernate.current_session_context_class"
                value="org.hibernate.context.ThreadLocalSessionContext" />
        </properties>
    </persistence-unit>
    <persistence-unit name="CassandraPU">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <class>com.example.kundera.Address</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="kundera.nodes" value="localhost" />
            <property name="kundera.port" value="9160" />
            <property name="kundera.keyspace" value="KunderaKeyspace" />
            <property name="kundera.dialect" value="cassandra" />
            <property name="kundera.client.lookup.class"
                value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
            <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.ddl.auto.prepare" value="create" />
        </properties>
    </persistence-unit>
</persistence>

KunderaDAO.java(Executor)

public class KunderaDAO {

    public static void main(String[] args) {

        //Persist Person entity
         Person person = new Person();

         person.setPersonId("1");
         person.setPersonName("John Smith");
         person.setPersonalData(new PersonalData("www.johnsmith.com", "john.smith@gmail.com", "jsmith"));

         Address address = new Address();
         address.setAddressId("111");
         address.setStreet("123, New street");
         person.setAddress(address);

         EntityManagerFactory emf = Persistence.createEntityManagerFactory("mysqlPU,CassandraPU");
         EntityManager em = emf.createEntityManager();
         System.out.println("EntityManager "+ em);
         em.persist(person);

         //Find Person Entity
         Person p = em.find(Person.class, "1");

         //Run JPA Query
         Query q = em.createQuery("select p from Person p");
         List<?> persons = q.getResultList();
         System.out.println("Person list: "+persons.lastIndexOf(1));

         em.close();
         emf.close();

    }

Output

Persists PERSON into RDBMS and ADDRESS into Cassandra

Hope it helps.

-Vivek

shiva404 commented 10 years ago

I did that. But its not working somehow. If you want I can share my code.

mevivs commented 10 years ago

Share your email id. Let me email you sample code, which i have tried

-Vivek

shiva404 commented 10 years ago

shiva.n404@gmail.com

mevivs commented 10 years ago

Any update?

shiva404 commented 10 years ago

No .. still issue not resolved. And it was looking unstable. I am not sure whether its a my mac machine problem or the build problem. And we mainly looking for RDBMS sharding support also.

mevivs commented 10 years ago

Scheduling for 2.10 release.

-Vivek

shiva404 commented 10 years ago

Cool.. thanks for the reply. Do you guys have timelines for 2.10 release? Any idea when it will get release?

mevivs commented 10 years ago

Scheduled for 31st january. Though I have verified and emailed you sample project with what i have verified. I will further have a look to test the same with different platforms and post an update on this.