-->
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.  [ 4 posts ] 
Author Message
 Post subject: persistence.xml not found when debugging code
PostPosted: Sat Feb 09, 2008 6:39 am 
Newbie

Joined: Fri Feb 08, 2008 10:31 pm
Posts: 4
I finallly got everything hooked up in eclipse to debug and see how the internals of hibernate work. I hooked up core, annotations, entitymanager, and jpa.

My problem occurs with jpa. when I step into it, the first thing I DO NOT see is it loading the persistence.xml file at all. Instead it is loading some PersistenceProvider.class in META-INF/services. Here is the code in Persistence.class.....(notice that there is no code that loads the persistence.xml but when I am using binary, it loads my persistence.xml file and Map properties allow me to override values....do I have the wrong source version from hibernate SVN or something????

public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
EntityManagerFactory emf = null;

if ( providers.size() == 0 ) {
findAllProviders();
}
for ( PersistenceProvider provider : providers ) {
emf = provider.createEntityManagerFactory( persistenceUnitName, properties );
if ( emf != null ) break;
}
if ( emf == null ) {
throw new PersistenceException( "No Persistence provider for EntityManager named " + persistenceUnitName );
}
return emf;
}

// Helper methods

private static void findAllProviders() {
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> resources = loader.getResources( "META-INF/services/" + PersistenceProvider.class.getName() );
Set<String> names = new HashSet<String>();
while ( resources.hasMoreElements() ) {
URL url = resources.nextElement();
InputStream is = url.openStream();
try {
names.addAll( providerNamesFromReader( new BufferedReader( new InputStreamReader( is ) ) ) );
}
finally {
is.close();
}
}
for ( String s : names ) {
Class providerClass = loader.loadClass( s );
providers.add( (PersistenceProvider) providerClass.newInstance() );
}
}
catch (IOException e) {
throw new PersistenceException( e );
}
catch (InstantiationException e) {
throw new PersistenceException( e );
}
catch (IllegalAccessException e) {
throw new PersistenceException( e );
}
catch (ClassNotFoundException e) {
throw new PersistenceException( e );
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 09, 2008 7:27 am 
Beginner
Beginner

Joined: Thu Jun 07, 2007 2:38 am
Posts: 28
Location: Italy, Rome
Do you use eclipse? And/or Maven?

Our persistence.xml was here and did not work well within eclipse and Maven:
/src/main/java/META-INF/persistence.xml

Now are persistence.xml is here and it works fine (eclipse and Maven):
/src/main/resources/META-INF/persistence.xml

Actually, /src/main/resources/META-INF/, is the place where it should be from a Maven perspective.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 10, 2008 9:18 pm 
Newbie

Joined: Fri Feb 08, 2008 10:31 pm
Posts: 4
actually, no, that's not why. I finally figured it out(too bad I can't get my credit back :( ). Anyways, if you look closely at the code above, it is loading a file from META-INF/services/" + PersistenceProvider.class.getName(). When you have hibernate source in your path and entitymgr in your path, etc. et., this file is not in the path anymore. If you use the hibernate binaries, it is in one of the jars. This file contains a single name of the Hibernate PersistenceProvider. That then loads the persistence.xml file. This is why it was not loading my persistence.xml file...it still had not loaded a PersistenceProvider.


Top
 Profile  
 
 Post subject: Re: persistence.xml not found when debugging code
PostPosted: Wed Mar 30, 2011 1:59 pm 
Newbie

Joined: Wed Mar 30, 2011 1:33 pm
Posts: 1
Thanks a lot erikvaningen!
It works for me =)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.