From: <gca...@us...> - 2013-02-14 15:33:01
|
Revision: 4192 http://openutils.svn.sourceforge.net/openutils/?rev=4192&view=rev Author: gcatania Date: 2013-02-14 15:32:53 +0000 (Thu, 14 Feb 2013) Log Message: ----------- BSHD-18 improve error message for missing hibernate entity mapping Modified Paths: -------------- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java Modified: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2013-02-04 16:09:42 UTC (rev 4191) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTree.java 2013-02-14 15:32:53 UTC (rev 4192) @@ -257,10 +257,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: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2013-02-04 16:09:42 UTC (rev 4191) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/ExampleTreeUtils.java 2013-02-14 15:32:53 UTC (rev 4192) @@ -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.spi.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: trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java =================================================================== --- trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2013-02-04 16:09:42 UTC (rev 4191) +++ trunk/openutils-bshd5/src/main/java/it/openutils/hibernate/example/FilterMetadataSupport.java 2013-02-14 15:32:53 UTC (rev 4192) @@ -111,10 +111,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. |