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

<exclude-unlisted-classes> on persistence.xml is not working #407

Closed pires closed 10 years ago

pires commented 11 years ago

I have a polyglot app that has two persistence-units, one with Hibernate as persistence provider, the other with Kundera 2.7.1 (kundera-cassandra).

Now, I have a single persistence.xml that looks like this:

<?xml version='1.0' encoding='utf-8'?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  version="2.1">
  <persistence-unit name="RDBMS_PU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/PolyglotDS</jta-data-source>

    <class>com.github.pires.polyglot.model.UserRDBMS</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

    <properties>
      <property name="hibernate.transaction.jta.platform"
        value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
      <property name="javax.persistence.schema-generation.database.action"
        value="drop-and-create" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
      <property name="hibernate.default_schema" value="public" />
      <property name="hibernate.listeners.envers.autoRegister"
        value="false" />
      <property name="hibernate.show_sql" value="false" />
      <property name="hibernate.default_batch_fetch_size"
        value="8" />
      <property name="hibernate.max_fetch_depth" value="3" />
      <property name="hibernate.cache.use_second_level_cache"
        value="true" />
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
      <property name="hibernate.cache.region.factory_class"
        value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
      <property name="hibernate.id.new_generator_mappings"
        value="true" />
    </properties>
  </persistence-unit>

  <persistence-unit name="NOSQL_PU">
    <provider>com.impetus.kundera.KunderaPersistence</provider>

    <class>com.github.pires.polyglot.model.UserNoSQL</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
      <property name="kundera.nodes"
        value="10.10.1.211,10.10.1.212,10.10.1.213,10.10.1.214" />
      <property name="kundera.port" value="9160" />
      <property name="kundera.keyspace" value="PolyglotKS" />
      <property name="kundera.dialect" value="cassandra" />
      <property name="kundera.client.lookup.class"
        value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
      <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" />
      <property name="kundera.client.property" value="kundera-cassandra.xml" />
    </properties>
  </persistence-unit>

</persistence>

Now, when deploying the app Hibernate works as expected. It validates current PostgreSQL schema and updates if needed. Needless is to say that it also ignores every class, except UserRDBMS. The same doesn't happen with Kundera that tries to deal with the aforementioned class when it should deal only with UserNoSQL entity.

Any hints?

pires commented 11 years ago

By the way, IIRC the JPA spec defines that <excluded-unlisted-classes> is true by default.

pires commented 10 years ago

This is a non-issue since I was lacking an entity ID (@Idannotation).

Nonetheless, I would suggest to improve the exception handling so that instead of having:

java.lang.NullPointerException
    at com.impetus.kundera.configure.MetamodelConfiguration.processGeneratedValueAnnotation(MetamodelConfiguration.java:490)
    at com.impetus.kundera.configure.MetamodelConfiguration.scanClassAndPutMetadata(MetamodelConfiguration.java:399)
    at com.impetus.kundera.configure.MetamodelConfiguration.loadEntityMetadata(MetamodelConfiguration.java:230)
    at com.impetus.kundera.configure.MetamodelConfiguration.configure(MetamodelConfiguration.java:102)
    at com.impetus.kundera.configure.Configurator.configure(Configurator.java:65)
    at com.impetus.kundera.KunderaPersistence.initializeKundera(KunderaPersistence.java:109)
    at com.impetus.kundera.KunderaPersistence.createEntityManagerFactory(KunderaPersistence.java:81)
    at com.impetus.kundera.KunderaPersistence.createContainerEntityManagerFactory(KunderaPersistence.java:65)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:199)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:107)
    at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
    at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
    at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
    at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)

One should see something like:

com.impetus.kundera.exception.MissingIdField

Thanks to @mevivs for helping with debugging.