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

Hibernate drops tables for relational database when using polyglot persistence #556

Closed makearl closed 10 years ago

makearl commented 10 years ago

Hi,

I was following the Polyglot Persistence example with a few mocked-out databases for Cassandra and MariaDB: https://github.com/impetus-opensource/Kundera/wiki/Polyglot-Persistence

When creating an EntityManagerFactory for Cassandra by itself or for MariaDB by itself, everything works as expected and I was able to persist objects.

When creating an EntityManagerFactory that references both connections like in the Polyglot Persistence example, hibernate tries to drop the tables used in my Entity Classes from MariaDB.

Here's how I'm initializing the EntityManagerFactory for Polyglot Persistence: Map propertyMap = new HashMap(); propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0); EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu,maria_pu", propertyMap); EntityManager em = emf.createEntityManager();

Here's the persistence.xml file being used:

<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="cassandra_pu">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <class>environment.model.User</class>
        <class>environment.model.SensorMessageRecord</class>
        <properties>
            <property name="kundera.nodes" value="localhost"/>
            <property name="kundera.port" value="9160"/>
            <property name="kundera.keyspace" value="environmentkeyspace"/>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
        </properties>
    </persistence-unit>
    <persistence-unit name="maria_pu">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <class>environment.model.Device</class>
        <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="org.mariadb.jdbc.Driver" />
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/environmentschema" />
            <property name="hibernate.connection.username" value="root" />
            <property name="hibernate.current_session_context_class" value="thread"/>
            <!--<property name="hibernate.connection.password" value="impetus" />-->
            <!--<property name="hibernate.current_session_context_class" value="org.hibernate.context.ThreadLocalSessionContext" />-->
        </properties>
    </persistence-unit>
</persistence>

Here's an example of the output when trying to run with both the Maria and Cassandra persistence objects: 1294 [main] INFO org.hibernate.validator.util.Version - Hibernate Validator 4.2.0.Final Hibernate: Drop table users 1628 [main] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1051, SQLState: 42S02 1628 [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Unknown table 'users' Hibernate: Drop table device Hibernate: Drop table sensor_test 1633 [main] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1051, SQLState: 42S02 1633 [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Unknown table 'sensor_test'

Additional Information: I built Kundera from the tip of github a few days ago.

impetus-opensource-admin commented 10 years ago

I have added a fix for this issue in current trunk. Schema drop would only happen in case opted for "hibernate.hbm2ddl.auto" with value as "create" or "create-drop".

Thanks, -Vivek

makearl commented 10 years ago

I built with the latest and this is resolved. Thanks!