HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties

1,107 views
Skip to first unread message

Nick

unread,
Mar 14, 2013, 3:25:11 PM3/14/13
to kundera...@googlegroups.com
Hi,
We are having some success using Kundera to persist our entities to a Cassandra database, but we would like to use an in-memory database to run our unit-tests, so that we have good coverage during continuous integration builds on our Jenkins server.
Obviously, there is an option to install and run Cassandra as a service on our Jenkins server, but it makes it much simpler to configure and run the build (and much simpler for the other developers).
We are using Spring to configure the emf and em, and injecting properties using the "jpaProperties" for the Spring emf. The persistence.xml is very small, with only constant values such as kundera.keyspace and kundera.cache.provider.class for the properties there.
My plan was to use the Pelops kundera.client for regular deployed usage, persisting to Cassandra, and to use the rdbms kundera.client for the unit tests that run during the build. Then my test configuration would use hibernate configurations to connect to a HSQL (or H2) in-memory database.
This configuration works fine for Pelops and the kundera.nodes, kundera.port, kundera.ddl.auto.prepare properties are passed through to the PelopsClientFactory during configuration. When we run the unit tests, the hibernate properties (hibernate.connection.url, hibernate.connection.driver_class, etc) are not passed through to the HibernateClient and we get the following error message:
WARN (ConnectionProviderInitiator.java:143) org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator - HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
I have traced through with the debugger and it seems that the HibernateClient constructor is not passing the supplied "puProperties" to the Configuration object that is created, it is only using the results of the call to HibernateUtils.getProperties(persistenceUnit) (which only sees the properties defined in the persistence.xml).
Why is it not possible to pass the "puProperties" into the configuration as well (or instead)?

Thanks,

Nick.

Vivek Mishra

unread,
Mar 14, 2013, 10:45:41 PM3/14/13
to kundera...@googlegroups.com
I agree, will post an update once this is supported. Here it is:
https://github.com/impetus-opensource/Kundera/issues/215

-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Nick [nick.the....@gmail.com]
Sent: 15 March 2013 00:55
To: kundera...@googlegroups.com
Subject: {kundera-discuss} HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties
--
You received this message because you are subscribed to the Google Groups "kundera-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kundera-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


________________________________






NOTE: This message may contain information that is confidential, proprietary, privileged or otherwise protected by law. The message is intended solely for the named addressee. If received in error, please destroy and notify the sender. Any use of this email is prohibited when received in error. Impetus does not represent, warrant and/or guarantee, that the integrity of this communication has been maintained nor that the communication is free of errors, virus, interception or interference.

Amresh

unread,
Apr 2, 2013, 10:15:08 AM4/2/13
to kundera...@googlegroups.com
Hi Nic,

I am working on this issue, have provided a fix and need your assistance in testing this scenario.

Could you please send me your code that you want to create EMF based on a configuration file. (A zip file of project would help better).

Sincerely,
Amresh


Nick James

unread,
Apr 3, 2013, 7:35:28 PM4/3/13
to kundera...@googlegroups.com
Attached is a zip file of the project,
Adjust the kundera.client, kundera.client.lookup.class and kundera.dialect properties in src/test/resources/persistence.properties to run against either Cassandra or Hibernate.
My unit tests failed at opening the entityManager, so I'm not 100% sure that the tests are configured to pass, but they should get further than:
  test_find_addresses_for_customer_query(com.digitalriver.arctic.model.integration.AddressDaoTest): Could not open JPA EntityManager for transaction; nested exception is org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
  test_find_customer_by_name_query(com.digitalriver.arctic.model.integration.CustomerDaoTest): Could not open JPA EntityManager for transaction; nested exception is org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
  test_basic_crud_operations(com.digitalriver.arctic.model.integration.ModelMappingTest): Could not open JPA EntityManager for transaction; nested exception is org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set

Thanks for looking into this for me.

BTW, I didn't know how to upload the project to the issue report directly. I hope it's okay to send it directly to your email.

thanks,

Nick.


--
You received this message because you are subscribed to a topic in the Google Groups "kundera-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kundera-discuss/GvUx9ylOTpg/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to kundera-discu...@googlegroups.com.
kundera-test.zip

Amresh Kumar Singh

unread,
Apr 4, 2013, 1:57:00 AM4/4/13
to kundera...@googlegroups.com
Thanks Nic!

I couldn't find source code and config file in attached Zip (src folder is empty)

Could you please try sending again.

Sincrely,
Amresh

From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Nick James [nick.the....@gmail.com]
Sent: Thursday, April 04, 2013 5:05 AM
To: kundera...@googlegroups.com
Subject: Re: {kundera-discuss} HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties

Nick James

unread,
Apr 4, 2013, 3:35:12 PM4/4/13
to kundera...@googlegroups.com
Sorry about that. Major fail with zip.
Attached is a better (I hope) zip file.

Thanks,

Nick.
kundera-test.zip

Nick

unread,
May 29, 2013, 3:58:06 PM5/29/13
to kundera...@googlegroups.com
Hi guys,
sorry if I'm a little unclear about the current state of this work. I have tried updating to kundera 2.5 and it gets a little further, so I am assuming that some work has been done on this.
My current state of play is that hibernate now gets beyond the configuration stage but the in-memory HSQL database that I am trying to use for my unit tests does not have any tables created before the persistence tests run. I tried to fix that by adding a new property, hibernate.hbm2ddl.auto set to a value of create. Unfortunately, hibernate fails to create the schema (which kundera insists upon having) and gives the following error:
2013-05-29 14:16:38,237 [main] DEBUG (SqlStatementLogger.java:104) org.hibernate.SQL - 
    create table Kunde...@kundera-test-persistence-unit.addresses (
        id varchar(255) not null,
        city varchar(255),
        line1 varchar(255),
        line2 varchar(255),
        last_updated timestamp not null,
        customer_id varchar(255),
        primary key (id)
    )
Hibernate: 
    create table Kunde...@kundera-test-persistence-unit.addresses (
        id varchar(255) not null,
        city varchar(255),
        line1 varchar(255),
        line2 varchar(255),
        last_updated timestamp not null,
        customer_id varchar(255),
        primary key (id)
    )
2013-05-29 14:16:38,237 [main] ERROR (SchemaExport.java:425) org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table Kunde...@kundera-test-persistence-unit.addresses (id varchar(255) not null, city varchar(255), line1 varchar(255), line2 varchar(255), last_updated timestamp not null, customer_id varchar(255), primary key (id))
2013-05-29 14:16:38,237 [main] ERROR (SchemaExport.java:426) org.hibernate.tool.hbm2ddl.SchemaExport - Unexpected token: @ in statement [
    create table KunderaTest]

On the hibernate forums and issues pages I see a reference to using a JPA 2.1 property: javax.persistence.schema-generation-source set to a value of metadata-then-script, but that has no effect (it was very optimistic:) )

Thanks for any thoughts,

Nick.

Vivek Mishra

unread,
May 29, 2013, 4:01:26 PM5/29/13
to kundera...@googlegroups.com
Any entity, which is intended for RDBMS should be annotated with @Table annotation but no schema name as:

@Table(name = "PERSON", schema = "testdb")
public class PersonRDBMS
{

Here, table name is PERSON and testdb is schema name.


Hope this helps.

-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Nick [nick.the....@gmail.com]
Sent: 30 May 2013 01:28
To: kundera...@googlegroups.com
Subject: Re: {kundera-discuss} HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties

Nick

unread,
May 30, 2013, 9:15:27 AM5/30/13
to kundera...@googlegroups.com
Thanks for an answer Vivek, but it really doesn't help me. Let me see if I understand correctly: My entities *must* have a schema name on the Table annotation to work with Kundera when persisting to Cassandra, but *cannot* have a schema name on the Table annotation when unit testing the same entities using an in-memory database and hibernate?

Thanks,

Nick.


On Wednesday, May 29, 2013 3:01:26 PM UTC-5, Vivek wrote:
Any entity, which is intended for RDBMS should be annotated with @Table annotation but no schema name as:

@Table(name = "PERSON", schema = "testdb")
public class PersonRDBMS
{

Here, table name is PERSON and testdb is schema name.


Hope this helps.

-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Nick [nick.the....@gmail.com]
Sent: 30 May 2013 01:28
To: kundera...@googlegroups.com
Subject: Re: {kundera-discuss} HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties

Hi guys,
sorry if I'm a little unclear about the current state of this work. I have tried updating to kundera 2.5 and it gets a little further, so I am assuming that some work has been done on this.
My current state of play is that hibernate now gets beyond the configuration stage but the in-memory HSQL database that I am trying to use for my unit tests does not have any tables created before the persistence tests run. I tried to fix that by adding a new property, hibernate.hbm2ddl.auto set to a value of create. Unfortunately, hibernate fails to create the schema (which kundera insists upon having) and gives the following error:
2013-05-29 14:16:38,237 [main] DEBUG (SqlStatementLogger.java:104) org.hibernate.SQL -
    create table KunderaTest@kundera-test-persistence-unit.addresses (
        id varchar(255) not null,
        city varchar(255),
        line1 varchar(255),
        line2 varchar(255),
        last_updated timestamp not null,
        customer_id varchar(255),
        primary key (id)
    )
Hibernate:
    create table KunderaTest@kundera-test-persistence-unit.addresses (
        id varchar(255) not null,
        city varchar(255),
        line1 varchar(255),
        line2 varchar(255),
        last_updated timestamp not null,
        customer_id varchar(255),
        primary key (id)
    )
2013-05-29 14:16:38,237 [main] ERROR (SchemaExport.java:425) org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table KunderaTest@kundera-test-persistence-unit.addresses (id varchar(255) not null, city varchar(255), line1 varchar(255), line2 varchar(255), last_updated timestamp not null, customer_id varchar(255), primary key (id))

Vivek Mishra

unread,
May 30, 2013, 9:24:21 AM5/30/13
to kundera...@googlegroups.com
The way schema name defines within Kundera is keyspace@persistenceunit .For RDBMS support Kundera relies on Hibernate which will not work with such definition, so that's why we suggest to skip schema name or provide schema name only without "@" .

Hope it helps.

-Vivek

________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Nick [nick.the....@gmail.com]
Sent: 30 May 2013 18:45
To: kundera...@googlegroups.com
Subject: Re: {kundera-discuss} HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties

Thanks for an answer Vivek, but it really doesn't help me. Let me see if I understand correctly: My entities *must* have a schema name on the Table annotation to work with Kundera when persisting to Cassandra, but *cannot* have a schema name on the Table annotation when unit testing the same entities using an in-memory database and hibernate?

Thanks,

Nick.

On Wednesday, May 29, 2013 3:01:26 PM UTC-5, Vivek wrote:
Any entity, which is intended for RDBMS should be annotated with @Table annotation but no schema name as:

@Table(name = "PERSON", schema = "testdb")
public class PersonRDBMS
{

Here, table name is PERSON and testdb is schema name.


Hope this helps.

-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Nick [nick.the....@gmail.com]
Sent: 30 May 2013 01:28
To: kundera...@googlegroups.com
Subject: Re: {kundera-discuss} HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties

Hi guys,
sorry if I'm a little unclear about the current state of this work. I have tried updating to kundera 2.5 and it gets a little further, so I am assuming that some work has been done on this.
My current state of play is that hibernate now gets beyond the configuration stage but the in-memory HSQL database that I am trying to use for my unit tests does not have any tables created before the persistence tests run. I tried to fix that by adding a new property, hibernate.hbm2ddl.auto set to a value of create. Unfortunately, hibernate fails to create the schema (which kundera insists upon having) and gives the following error:
2013-05-29 14:16:38,237 [main] DEBUG (SqlStatementLogger.java:104) org.hibernate.SQL -
create table Kunde...@kundera-test-persistence-unit.addresses (
id varchar(255) not null,
city varchar(255),
line1 varchar(255),
line2 varchar(255),
last_updated timestamp not null,
customer_id varchar(255),
primary key (id)
)
Hibernate:
create table Kunde...@kundera-test-persistence-unit.addresses (
id varchar(255) not null,
city varchar(255),
line1 varchar(255),
line2 varchar(255),
last_updated timestamp not null,
customer_id varchar(255),
primary key (id)
)
2013-05-29 14:16:38,237 [main] ERROR (SchemaExport.java:425) org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table Kunde...@kundera-test-persistence-unit.addresses (id varchar(255) not null, city varchar(255), line1 varchar(255), line2 varchar(255), last_updated timestamp not null, customer_id varchar(255), primary key (id))

Nick

unread,
May 30, 2013, 10:00:45 AM5/30/13
to kundera...@googlegroups.com
Thanks for the quick response. Is it possible to "hook into" the metadata at start up of the unit tests, to remove the "schema" attributes of all the entities?
Or (better) provide a property to be used for the schema, which would be set to <keyspace>@<persistent-unit> for Cassandra, but empty for the unit tests under hibernate? @Table (schema="${schema-name}"...) ?

Thanks,

Nick.
    create table KunderaTest@kundera-test-persistence-unit.addresses (
        id varchar(255) not null,
        city varchar(255),
        line1 varchar(255),
        line2 varchar(255),
        last_updated timestamp not null,
        customer_id varchar(255),
        primary key (id)
    )
Hibernate:
    create table KunderaTest@kundera-test-persistence-unit.addresses (
        id varchar(255) not null,
        city varchar(255),
        line1 varchar(255),
        line2 varchar(255),
        last_updated timestamp not null,
        customer_id varchar(255),
        primary key (id)
    )
2013-05-29 14:16:38,237 [main] ERROR (SchemaExport.java:425) org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table KunderaTest@kundera-test-persistence-unit.addresses (id varchar(255) not null, city varchar(255), line1 varchar(255), line2 varchar(255), last_updated timestamp not null, customer_id varchar(255), primary key (id))

Vivek Mishra

unread,
May 30, 2013, 10:18:29 AM5/30/13
to kundera...@googlegroups.com
Hi Nick,
Please see if you find this thread useful:

https://groups.google.com/forum/#!searchin/kundera-discuss/EntityMetadata/kundera-discuss/YY0V2EiWL9M/WXZiYaboAI8J


-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Nick [nick.the....@gmail.com]
Sent: 30 May 2013 19:30
create table Kunde...@kundera-test-persistence-unit.addresses (
id varchar(255) not null,
city varchar(255),
line1 varchar(255),
line2 varchar(255),
last_updated timestamp not null,
customer_id varchar(255),
primary key (id)
)
Hibernate:
create table Kunde...@kundera-test-persistence-unit.addresses (
id varchar(255) not null,
city varchar(255),
line1 varchar(255),
line2 varchar(255),
last_updated timestamp not null,
customer_id varchar(255),
primary key (id)
)
2013-05-29 14:16:38,237 [main] ERROR (SchemaExport.java:425) org.hibernate.tool.hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table Kunde...@kundera-test-persistence-unit.addresses (id varchar(255) not null, city varchar(255), line1 varchar(255), line2 varchar(255), last_updated timestamp not null, customer_id varchar(255), primary key (id))

Vivek Mishra

unread,
Jul 29, 2013, 5:54:39 AM7/29/13
to kundera...@googlegroups.com
Support has been added for this.
Please see https://github.com/impetus-opensource/Kundera/issues/215 for more on this.

-Vivek
________________________________________
From: kundera...@googlegroups.com [kundera...@googlegroups.com] on behalf of Vivek Mishra
Sent: 30 May 2013 19:48
To: kundera...@googlegroups.com
Subject: RE: {kundera-discuss} HIbernate configuration only sees persistence.xml properties and not Spring EntityManagerFactory configured properties
Reply all
Reply to author
Forward
0 new messages