-->
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: MetaAttribute.getValue IllegalStateException no unique value
PostPosted: Tue Mar 08, 2005 1:28 pm 
Newbie

Joined: Tue Oct 05, 2004 11:28 am
Posts: 10
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.


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.