-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: persistence.xml location in a multi-module project
PostPosted: Mon Mar 21, 2016 11:54 am 
Newbie

Joined: Mon Mar 21, 2016 11:31 am
Posts: 3
Hi,

at the moment I'm working on a MongoDB EAR-project using Wildfly 10. As an additional persistence layer I would like to use Hibernate OGM 5. My project consists of multiple EJB modules of which several use the MongoDB database.

I added the OGM modules to an EJB as described in the documentation. I put a persistence.xml to the META-INF directory of the same module, too. Everything works as expected.

Now my questions/problem:

- If I create a similar project with a traditional datasource in WF I am able to create a config module with the persistence.xml, add this module as a dependency to other EJB modules. In such a configuration all entities in all modules are auto discovered (no need to put them in the persistence.xml) and I need to add the persistence.xml just once. Is it possible to achive the same behaviour when using Hibernate OGM?

- If this is not possible, do I have to put a persistence.xml file in every EJB module? Is auto-discovery possible in such a configuration? Is the connection between the modules shared or does every EJB open up it's own connection to the MongoDB database?

- Are there better ways to configure OGM persistence in such an environment?

If I should provide additional information, please let me know. Thanks in advance for your help.

Dieter


Top
 Profile  
 
 Post subject: Re: persistence.xml location in a multi-module project
PostPosted: Mon Mar 21, 2016 3:01 pm 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,

Quote:
Everything works as expected.


Awesome :)

Quote:
If I create a similar project with a traditional datasource in WF I am able to create a config module with the persistence.xml, add this module as a dependency to other EJB modules. In such a configuration all entities in all modules are auto discovered (no need to put them in the persistence.xml) and I need to add the persistence.xml just once. Is it possible to achive the same behaviour when using Hibernate OGM?


I haven't tested this but if it was working before it should work now as well. Are you asking because you tried and it does not work?

Quote:
If this is not possible, do I have to put a persistence.xml file in every EJB module? Is auto-discovery possible in such a configuration? Is the connection between the modules shared or does every EJB open up it's own connection to the MongoDB database?


At the moment, every EJB will have it's own connection.

You should be able to configure OGM in the same way you configure ORM or another JPA implementation, the main difference is that you cannot configure datasources or JDBC connections.

I hope this help, please let us know if there is some use case that does not work and we will check.

Cheers,
Davide


Top
 Profile  
 
 Post subject: Re: persistence.xml location in a multi-module project
PostPosted: Mon Mar 21, 2016 4:23 pm 
Newbie

Joined: Mon Mar 21, 2016 11:31 am
Posts: 3
Hi,

Quote:
Quote:
If I create a similar project with a traditional datasource in WF I am able to create a config module with the persistence.xml, add this module as a dependency to other EJB modules. In such a configuration all entities in all modules are auto discovered (no need to put them in the persistence.xml) and I need to add the persistence.xml just once. Is it possible to achive the same behaviour when using Hibernate OGM?

I haven't tested this but if it was working before it should work now as well. Are you asking because you tried and it does not work?

To be a little bit more precise, I tested it with the Hibernate OR(!)M mapper used in Wildfly. The config module with the persistence.xml (that contains a JNDI datasource) is a dependency for all dependent EJB modules using the persistence context. In such a config there's no need to list the classes in the persistence.xml (auto-discovery). It's not even possible because the Entities are unknown to the config module. This is what I tested. And it worked.
Quote:
Quote:
If this is not possible, do I have to put a persistence.xml file in every EJB module? Is auto-discovery possible in such a configuration? Is the connection between the modules shared or does every EJB open up it's own connection to the MongoDB database?

At the moment, every EJB will have it's own connection.
You should be able to configure OGM in the same way you configure ORM or another JPA implementation, the main difference is that you cannot configure datasources or JDBC connections.

In your answer I read between the lines that my above scenario is not possible, because I cannot reuse the persistence context from a dependency. Do you know if auto-discovery of entities is possible? When I do not list the classes in the persistence.xml they are not discovered. I can post my persistence.xml file if you want, but it looks like the one from the docs.

Thanks for your help.

Dieter


Top
 Profile  
 
 Post subject: Re: persistence.xml location in a multi-module project
PostPosted: Tue Mar 22, 2016 7:54 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
I checked the JPA 2 specification (paragraph 8.2.2 Persistence Unit Scope):

Quote:
A persistence unit that is defined at the level of an EJB-JAR, WAR, or application client jar is
scoped to that EJB-JAR, WAR, or application jar respectively and is visible to the components
defined in that jar or war


OGM should work in the same way, if you find that something is not matching, please, provide us with an example and we will check.

I hope this help,
Davide


Top
 Profile  
 
 Post subject: Re: persistence.xml location in a multi-module project
PostPosted: Tue Mar 22, 2016 7:59 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
In the meanwhile,
I've created an issue to add an integration test: https://hibernate.atlassian.net/browse/OGM-999

If you can describe your use case we can add it to our build.

Cheers,
Davide


Top
 Profile  
 
 Post subject: Re: persistence.xml location in a multi-module project
PostPosted: Wed Mar 23, 2016 2:37 am 
Newbie

Joined: Mon Mar 21, 2016 11:31 am
Posts: 3
Hello,

thanks for your comment.

It will take a while to create the example, because I must strip down my project to the relevant parts. Can you say something about auto-discovery of entities?

Dieter


Top
 Profile  
 
 Post subject: Re: persistence.xml location in a multi-module project
PostPosted: Wed Mar 23, 2016 8:09 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Auto-discovery is defined as well by the spec (8.2.1.6.1):

Quote:
All classes contained in the root of the persistence unit are searched for annotated managed persistence
classes—classes with the Entity, Embeddable, or MappedSuperclass annotation—and any
mapping metadata annotations found on these classes will be processed, or they will be mapped using
the mapping annotation defaults.


So, it should be able to auto-discover the classes contained in the same JAR where the persistence-unit is defined.

You can also set the jar-file property in the persistence.xml to define a JAR containing the mapping files (I'm not sure if this can help).

Davide


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.