[hibernate-commits] Hibernate SVN: r14274 - entitymanager/trunk/src/java/org/hibernate/ejb.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jan 15 15:53:17 EST 2008


Author: epbernard
Date: 2008-01-15 15:53:17 -0500 (Tue, 15 Jan 2008)
New Revision: 14274

Modified:
   entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java
Log:
EJB-325 PersistenceException were missing the PU name

Modified: entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java	2008-01-15 19:25:10 UTC (rev 14273)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/Ejb3Configuration.java	2008-01-15 20:53:17 UTC (rev 14274)
@@ -105,6 +105,7 @@
 	private static Log log = LogFactory.getLog( Ejb3Configuration.class );
 	private static EntityNotFoundDelegate ejb3EntityNotFoundDelegate = new Ejb3EntityNotFoundDelegate();
 	private static Configuration DEFAULT_CONFIGURATION = new AnnotationConfiguration();
+	private String persistenceUnitName;
 
 	private static class Ejb3EntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable {
 		public void handleEntityNotFound(String entityName, Serializable id) {
@@ -157,6 +158,7 @@
 
 		Map workingVars = new HashMap();
 		workingVars.put( HibernatePersistence.PERSISTENCE_UNIT_NAME, metadata.getName() );
+		this.persistenceUnitName = metadata.getName();
 
 		if ( StringHelper.isNotEmpty( metadata.getJtaDatasource() ) ) {
 			this.setProperty( Environment.DATASOURCE, metadata.getJtaDatasource() );
@@ -259,7 +261,7 @@
 				throw (PersistenceException) e;
 			}
 			else {
-				throw new PersistenceException( e );
+				throw new PersistenceException( getExceptionHeader() + "Unable to configure EntityManagerFactory", e );
 			}
 		}
 	}
@@ -339,6 +341,7 @@
 		try {
 			Map workingVars = new HashMap();
 			workingVars.put( HibernatePersistence.PERSISTENCE_UNIT_NAME, info.getPersistenceUnitName() );
+			this.persistenceUnitName = info.getPersistenceUnitName();
 			List<String> entities = new ArrayList<String>( 50 );
 			if ( info.getManagedClassNames() != null ) entities.addAll( info.getManagedClassNames() );
 			List<NamedInputStream> hbmFiles = new ArrayList<NamedInputStream>();
@@ -519,7 +522,7 @@
 			transactionType = (PersistenceUnitTransactionType) overridenTxType;
 		}
 		else {
-			throw new PersistenceException( getExceptionHeader( workingVars ) +
+			throw new PersistenceException( getExceptionHeader() +
 					HibernatePersistence.TRANSACTION_TYPE + " of the wrong class type"
 							+ ": " + overridenTxType.getClass()
 			);
@@ -669,7 +672,7 @@
 			);
 		}
 		catch (HibernateException e) {
-			throw new PersistenceException( e );
+			throw new PersistenceException( getExceptionHeader() + "Unable to build EntityManagerFactory", e );
 		}
 		finally {
 			if (thread != null) {
@@ -763,22 +766,22 @@
 			}
 			catch (ClassNotFoundException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Unable to find interceptor class: " + interceptorName, e
+						getExceptionHeader() + "Unable to find interceptor class: " + interceptorName, e
 				);
 			}
 			catch (IllegalAccessException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Unable to access interceptor class: " + interceptorName, e
+						getExceptionHeader() + "Unable to access interceptor class: " + interceptorName, e
 				);
 			}
 			catch (InstantiationException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Unable to instanciate interceptor class: " + interceptorName, e
+						getExceptionHeader() + "Unable to instanciate interceptor class: " + interceptorName, e
 				);
 			}
 			catch (ClassCastException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Interceptor class does not implement Interceptor interface: " + interceptorName, e
+						getExceptionHeader() + "Interceptor class does not implement Interceptor interface: " + interceptorName, e
 				);
 			}
 		}
@@ -793,22 +796,22 @@
 			}
 			catch (ClassNotFoundException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Unable to find naming strategy class: " + namingStrategyName, e
+						getExceptionHeader() + "Unable to find naming strategy class: " + namingStrategyName, e
 				);
 			}
 			catch (IllegalAccessException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Unable to access naming strategy class: " + namingStrategyName, e
+						getExceptionHeader() + "Unable to access naming strategy class: " + namingStrategyName, e
 				);
 			}
 			catch (InstantiationException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Unable to instanciate naming strategy class: " + namingStrategyName, e
+						getExceptionHeader() + "Unable to instanciate naming strategy class: " + namingStrategyName, e
 				);
 			}
 			catch (ClassCastException e) {
 				throw new PersistenceException(
-						getExceptionHeader(workingVars) + "Naming strategyy class does not implement NmaingStrategy interface: " + namingStrategyName,
+						getExceptionHeader() + "Naming strategyy class does not implement NmaingStrategy interface: " + namingStrategyName,
 						e
 				);
 			}
@@ -866,7 +869,7 @@
 				}
 				catch( MappingNotFoundException e ) {
 					if ( ! xmlFile.endsWith( META_INF_ORM_XML ) ) {
-						throw new PersistenceException( getExceptionHeader(workingVars)
+						throw new PersistenceException( getExceptionHeader()
 								+ "Unable to find XML mapping file in classpath: " + xmlFile);
 					}
 					else {
@@ -875,15 +878,15 @@
 					}
 				}
 				catch( MappingException me ) {
-					throw new PersistenceException( getExceptionHeader(workingVars)
+					throw new PersistenceException( getExceptionHeader()
 								+ "Error while reading JPA XML file: " + xmlFile, me);
 				}
 				if ( log.isInfoEnabled() ) {
 					if ( Boolean.TRUE.equals( useMetaInf ) ) {
-						log.info( getExceptionHeader( workingVars ) + META_INF_ORM_XML + " found");
+						log.info( getExceptionHeader() + META_INF_ORM_XML + " found");
 					}
 					else if (Boolean.FALSE.equals( useMetaInf ) ) {
-						log.info( getExceptionHeader( workingVars ) + "no " + META_INF_ORM_XML + " found");
+						log.info( getExceptionHeader() + "no " + META_INF_ORM_XML + " found");
 					}
 				}
 			}
@@ -910,12 +913,9 @@
 		}
 	}
 
-	private String getExceptionHeader(Map workingVars) {
-		if ( workingVars != null ) {
-			String puName = (String) workingVars.get( HibernatePersistence.PERSISTENCE_UNIT_NAME);
-			puName = puName == null ? "" : puName;
-			String header = "[PersistenceUnit: " + puName + "] ";
-			return header;
+	private String getExceptionHeader() {
+		if ( StringHelper.isNotEmpty( persistenceUnitName ) ) {
+			return "[PersistenceUnit: " + persistenceUnitName + "] ";
 		}
 		else {
 			return "";
@@ -991,7 +991,7 @@
 					isClass ? HibernatePersistence.CLASS_CACHE_PREFIX : HibernatePersistence.COLLECTION_CACHE_PREFIX
 			);
 			error.append( ": " ).append( propertyKey ).append( " " ).append( value );
-			throw new PersistenceException( getExceptionHeader(workingVars) + error.toString() );
+			throw new PersistenceException( getExceptionHeader() + error.toString() );
 		}
 		String usage = params.nextToken();
 		String region = null;
@@ -1013,7 +1013,7 @@
 	private void addSecurity(List<String> keys, Map properties, Map workingVars) {
 		log.debug( "Adding security" );
 		if ( !properties.containsKey( HibernatePersistence.JACC_CONTEXT_ID ) ) {
-			throw new PersistenceException( getExceptionHeader(workingVars) +
+			throw new PersistenceException( getExceptionHeader() +
 					"Entities have been configured for JACC, but "
 							+ HibernatePersistence.JACC_CONTEXT_ID
 							+ " has not been set"
@@ -1034,7 +1034,7 @@
 				jaccCfg.addPermission( role, clazz, actions );
 			}
 			catch (IndexOutOfBoundsException e) {
-				throw new PersistenceException( getExceptionHeader(workingVars) +
+				throw new PersistenceException( getExceptionHeader() +
 						"Illegal usage of " + HibernatePersistence.JACC_PREFIX + ": " + key );
 			}
 		}
@@ -1057,7 +1057,7 @@
 					pkg = null;
 				}
 				if ( pkg == null ) {
-					throw new PersistenceException( getExceptionHeader(workingVars) +  "class or package not found", cnfe );
+					throw new PersistenceException( getExceptionHeader() +  "class or package not found", cnfe );
 				}
 				else {
 					cfg.addPackage( name );




More information about the hibernate-commits mailing list