-->
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.  [ 1 post ] 
Author Message
 Post subject: exception in HibernatePersistence.createEntityManagerFactory
PostPosted: Thu Jun 14, 2007 4:48 pm 
Newbie

Joined: Thu Jun 14, 2007 1:33 pm
Posts: 1
Does anyone know how to force HibernatePersistence.createEntityManagerFactory to return a null if it cannot find the requested persistence-unit?

I have an application where I have multiple persistence providers on my classpath (toplink and hibernate). In my persistence.xml I have a single persistence-unit specifying a toplink provider. When I call javax.persistence.Persistence.createEntityManagerFactory() with my persistence-unit, I get the following HibernateException: "Hibernate Dialect must be explicitly set"

I ran it again and stepped into javax.persistence.Persistence.createEntityManagerFactory() to see what was going on. The code in this method is simple. Iterate over all known providers and try to create an EntityManagerFactory. If null is returned assume there is no persistence-unit for the current provider and move on to the next. If no provider can create an EntityManagerFactory, then throw the following exception: "No Persistence provider for EntityManager named ..."

I did not see a problem with this code so I dove deeper. It turns out that the Hibernate provider is the first provider in the list. I have no persistence.xml that specifies Hibernate as the provider, nor do I have a hibernate.properties. All I have is the provider.

On line 3 of HibernatePersistence.createEntityManagerFactory, cfg.configure() does nothing because there is no Hibernate persistence-unit, so the override properties are thrown away. Now there are no Hibernate properties specified, so when cfg.buildEntityManagerFactory() executes, an exception is thrown because there is no dialect or databasename. This is bad. I would assume that cfg.buildEntityManagerFactory() would return null if it could not create the desired EntityManagerFactory.

Now, I tried to work around this by providing a hibernate.properties file with some dummy values. Surprisingly
, HibernatePersistence.createEntityManagerFactory returned me an EntityManagerFactory. It should not because there is no persistence.xml on my classpath that specifies hibernate as a provider and has the requested persistence-unit.

Is there anyway I can make this work without re-writing HibernatePersistence.createEntityManagerFactory or javax.persistence.Persistence.createEntityManagerFactory?


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

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.