-->
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: Dynamic PersistenceUnitInfo.getJarFileUrls
PostPosted: Mon Feb 22, 2016 5:31 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
Hi,

For experimenting purposes (so don't shoot at me :-)), I am trying to split my entities in multiple jars (while keeping a single PU) and I would like to find a way to tell hibernate to dynamically discover all those jars without having to list them in persistence.xml <jar-file/>. (That's my challenge for today.)

My first idea was to implement my own PersistenceProvider which would delegate to org.hibernate.jpa.HibernatePeristenceProvider while overriding the getJarFileUrls() of the PersistenceUnitInfo passed to createContainerEntityManagerFactory() to find all jars on the classpath which contain a particular file (say META-INF/module.xml).

The problem is that it does not work: my jar files are not added to the persistence unit because it is not fully integrated with the application server (I am using wildfly 10 BTW).

So I tried specifying, jboss.as.jpa.adapterModule = org.hibernate.jipijapa-hibernate5 in my persistence.xml to make the integration happen but then it won't use my custom PersistenceProvider (I think the provider is overridden with org.hiberate.jpa.HibernatePersistenceProvider).

I also tried with jboss.as.jpa.providerModule = application to force it to use my provider but it does not work either.

So before, I implement my own jipijapa adaptor for my use case, I would like to know if there exists some SPI in hibernate which would let me plug my own strategy for adding <jar-file/>s; there's already a org.hibernate.boot.archive.scan.spi.Scanner to scan for classes and resources in a PU, could it be tweaked to find all my jars?

Thanks,

Xavier


Top
 Profile  
 
 Post subject: Re: Dynamic PersistenceUnitInfo.getJarFileUrls
PostPosted: Mon Feb 22, 2016 8:19 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
in the meantime, I have extended org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor, set jboss.as.jpa.adapterClass = ...CustomHibernatePersistenceProviderAdaptor in persistence.xml

Code:
public class CustomHibernatePersistenceProviderAdaptor extends HibernatePersistenceProviderAdaptor {
   
   public @Override void addProviderDependencies(PersistenceUnitMetadata pu) {
      pu.setJarFileUrls(detectJarFileUrls());
      super.addProviderDependencies(pu);
   }
...


Top
 Profile  
 
 Post subject: Re: Dynamic PersistenceUnitInfo.getJarFileUrls
PostPosted: Mon Feb 22, 2016 10:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Make sure that auto-discovery is enabled:

Code:
<property name="hibernate.archive.autodetection" value="class, hbm" />


Then you can list all the jars where you have entities:

Code:
<jar-file>lib/entities1.jar</jar-file>
<jar-file>lib/entities2.jar</jar-file>


Top
 Profile  
 
 Post subject: Re: Dynamic PersistenceUnitInfo.getJarFileUrls
PostPosted: Mon Feb 22, 2016 10:41 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
Thanks for your answer but, as I said in my first post, I wanted to create a single PU from multiple jars without explicitly listing those jars (or the entities) in persistence.xml (I wanted those jars to be auto-discovered based on the presence of a particular resource inside them).

I (naively) thought that just implementing my own PersistenceProvider (which would do the discovering in getJarFileUrls()) would be sufficient but I needed an jipijapa adaptor for it work in wildfly.


Top
 Profile  
 
 Post subject: Re: Dynamic PersistenceUnitInfo.getJarFileUrls
PostPosted: Mon Feb 22, 2016 2:55 pm 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
In the end, I implemented this feature with org.hibernate.boot.spi.MetadataSourcesContributor.


Top
 Profile  
 
 Post subject: Re: Dynamic PersistenceUnitInfo.getJarFileUrls
PostPosted: Fri Mar 18, 2016 3:31 pm 
Newbie

Joined: Thu Dec 28, 2006 12:24 pm
Posts: 5
Location: Brazil
kalgon wrote:
In the end, I implemented this feature with org.hibernate.boot.spi.MetadataSourcesContributor.


How you do to Hibernate start your MetadataSourcesContributor?

Allready did. Just file on META-INF


Top
 Profile  
 
 Post subject: Re: Dynamic PersistenceUnitInfo.getJarFileUrls
PostPosted: Tue Mar 22, 2016 10:35 am 
Beginner
Beginner

Joined: Mon Jul 05, 2004 9:29 am
Posts: 38
skull wrote:
How you do to Hibernate start your MetadataSourcesContributor?


I put my class name in META-INF/services/org.hibernate.boot.spi.MetadataSourcesContributor


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.