-->
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.  [ 3 posts ] 
Author Message
 Post subject: Accessing Meta model for Validation
PostPosted: Fri Mar 10, 2006 1:52 pm 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
I have several embedded hbm.xml configuration files which contain Length attributes for the properties. What is the best way to access that length information at runtime so I can add simple validation?

thanks,
craig


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 11, 2006 7:02 pm 
Beginner
Beginner

Joined: Sat Dec 10, 2005 6:22 pm
Posts: 28
Location: Chicago, IL
You can use the NHibernate.Mapping.Attributes to tag your classes and build your mapping files. You can then use attribute reflection to get at these properties. Check out the Nhibernate.Mapping.Attributes project under NHibernateContrib.

The only other way to do it within NHibernate would be to somehow get a handle to the SessionFactoryImpl class so you can get the mapped SqlType of the property. I believe it is only the SqlType that contains the length parameter.

You can call GetClassMetaData on the ISessionFactory to retrieve the metadata but I think this is useless unless you can somehow get a handle to the mapped SqlType. There is a function on the IType interface to get the SqlType but it requires an instance of the IMapping interface. The only object I know of implementing the IMapping interface is the SessionFactoryImpl. I do not think there is a clean way to get this but you can probably force a cast somewhere if your desperate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 1:41 pm 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
Thanks for the suggestion. Since I don't use the mapping attributes, I am going to try the GetClassMetaData and see where it takes me. I'll let you know if I have any success.

craig


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.