Hibernate version:
3.0 RC1
Mapping documents:
Code:
<class ...
<meta attribute="prettyName">Pretty Class Name</meta>
<property ...
<meta attribute="prettyName">Pretty Property Name</meta>
</property>
</class>
Code between sessionFactory.openSession() and session.close():Code:
PersistentClass pc = configuration.getClassMapping(someObject.getClass().getName());
for ( Iterator it = pc.getPropertyIterator() ; it.hasNext() ; ) {
Property p = (Property) it.next();
MetaAttribute ma = p.getMetaAttribute("prettyName");
System.out.println(ma.getValue());
// I made up this example - it might be wrong because my real code would not illustrate the issue very well
}
Partial stack trace of any exception that occurs:Code:
java.lang.IllegalStateException: no unique value
at org.hibernate.mapping.MetaAttribute.getValue(MetaAttribute.java:33)
at ...
Name and version of the database you are using:MySQL 4.17
I use the <meta> element to tie 'pretty' displayable names to columns, so that when a field is not provided by a user on a web form I can lookup the meta data for the class/property to automatically generate nice error messages.
After migrating to Hibernate 3.0, the <meta> attribute values are coalesced for all child elements in the mapping by default. I was using the attribute="prettyName" for meta elements in the <class> and also in the <property>, <many-to-one>, etc. child elements. This caused the call to MetaAttribute.getValue() to throw an IllegalStateException with the message "no unique value".
I corrected this problem by using the
inherit="false" attribute on the <meta> element in the <class> and got the behavior back to the way I liked it. I suppose I could have also used unique attribute names in the parent and child elements.
Code:
<class ...
<meta attribute="prettyName" inherit="false">Pretty Class Name</meta>
<property ...
<meta attribute="prettyName">Pretty Property Name</meta>
</property>
</class>
Note that the inherit="false" was only necessary on the parent <class> element.
I welcome any criticism/feedback/advice concerning this problem and/or my solution.