|
From: <gca...@us...> - 2013-02-14 15:58:53
|
Revision: 4193
http://openutils.svn.sourceforge.net/openutils/?rev=4193&view=rev
Author: gcatania
Date: 2013-02-14 15:58:42 +0000 (Thu, 14 Feb 2013)
Log Message:
-----------
Merged revisions 4192 via svnmerge from
https://openutils.svn.sourceforge.net/svnroot/openutils/trunk/openutils-bshd5
........
r4192 | gcatania | 2013-02-14 16:32:53 +0100 (gio, 14 feb 2013) | 1 line
BSHD-18 improve error message for missing hibernate entity mapping
........
Revision Links:
--------------
http://openutils.svn.sourceforge.net/openutils/?rev=4192&view=rev
Modified Paths:
--------------
branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java
branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java
branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java
Property Changed:
----------------
branches/openutils-bshd5-backport/
branches/openutils-bshd5-backport/src/
Property changes on: branches/openutils-bshd5-backport
___________________________________________________________________
Modified: svnmerge-integrated
- /trunk/openutils-bshd5:1-4040,4042-4056,4058-4092
+ /trunk/openutils-bshd5:1-4040,4042-4056,4058-4092,4192
Modified: svn:mergeinfo
- /trunk/openutils-bshd5:4045-4047*,4057,4059,4069-4070*,4073*,4075-4078*,4080*,4082*,4084-4085*,4087*,4089*,4091-4092*
+ /trunk/openutils-bshd5:4045-4047*,4057,4059,4069-4070*,4073*,4075-4078*,4080*,4082*,4084-4085*,4087*,4089*,4091-4092*,4192*
Property changes on: branches/openutils-bshd5-backport/src
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/openutils-bshd5/src:4045-4047,4057,4069-4070,4073,4075-4078,4080,4082,4084-4085,4087,4089,4091-4092
+ /trunk/openutils-bshd5/src:4045-4047,4057,4069-4070,4073,4075-4078,4080,4082,4084-4085,4087,4089,4091-4092,4192
Modified: branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java
===================================================================
--- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2013-02-14 15:32:53 UTC (rev 4192)
+++ branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2013-02-14 15:58:42 UTC (rev 4193)
@@ -261,10 +261,9 @@
{
crit.add(c);
}
- ClassMetadata classMetadata = sessionFactory.getClassMetadata(Hibernate.getClass(entity));
+ ClassMetadata classMetadata = ExampleTreeUtils.getClassMetadata(entity, sessionFactory);
ExampleTreeUtils.addIdentifierRestriction(crit, entity, classMetadata, sessionFactory.getCurrentSession()); // BSHD-11
-
Type[] types = classMetadata.getPropertyTypes();
String[] names = classMetadata.getPropertyNames();
for (int i = 0; i < types.length; i++)
Modified: branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java
===================================================================
--- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2013-02-14 15:32:53 UTC (rev 4192)
+++ branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2013-02-14 15:58:42 UTC (rev 4193)
@@ -31,7 +31,9 @@
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
+import org.hibernate.Hibernate;
import org.hibernate.Session;
+import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.metadata.ClassMetadata;
@@ -106,7 +108,8 @@
}
if (size > 1)
{
- throw new IllegalArgumentException("More than one element in filter collection is unsupported.");
+ throw new IllegalArgumentException("More than one element in filter collection is unsupported.\n"
+ + coll);
}
}
Class< ? extends Object> clazz = collectionValue.getClass();
@@ -128,6 +131,25 @@
}
/**
+ * obtains the hibernate class metadata for the input entity
+ * @param entity the hibernate entity
+ * @param sessionFactory the session factory to retrieve metadata from
+ * @return the class metadata
+ * @throws IllegalStateException if no class metadata is configured for the input entity
+ */
+ public static ClassMetadata getClassMetadata(Object entity, SessionFactory sessionFactory)
+ throws IllegalStateException
+ {
+ Class< ? > cl = Hibernate.getClass(entity);
+ ClassMetadata classMetadata = sessionFactory.getClassMetadata(cl);
+ if (classMetadata == null)
+ {
+ throw new IllegalStateException("No hibernate class metadata found for: " + cl);
+ }
+ return classMetadata;
+ }
+
+ /**
* @param strings an array of strings
* @param s the string to append
* @return a new array containing the input string array plus the input string at the end
Modified: branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java
===================================================================
--- branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2013-02-14 15:32:53 UTC (rev 4192)
+++ branches/openutils-bshd5-backport/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2013-02-14 15:58:42 UTC (rev 4193)
@@ -115,10 +115,9 @@
String path = ExampleTreeUtils.getPath(walkedProperties);
Map<String, FilterMetadata> currFilterMetadata = getFilterMetadata(path);
crit.add(example(entity, currFilterMetadata.keySet()));
- ClassMetadata classMetadata = sessionFactory.getClassMetadata(Hibernate.getClass(entity));
+ ClassMetadata classMetadata = ExampleTreeUtils.getClassMetadata(entity, sessionFactory);
ExampleTreeUtils.addIdentifierRestriction(crit, entity, classMetadata, sessionFactory.getCurrentSession()); // BSHD-11
-
Type[] types = classMetadata.getPropertyTypes();
String[] names = classMetadata.getPropertyNames();
for (int i = 0; i < types.length; i++)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|