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.  [ 7 posts ] 
Author Message
 Post subject: Accessing sql-type in the metadata
PostPosted: Sat Sep 02, 2006 7:44 am 
Newbie

Joined: Sat Sep 02, 2006 7:27 am
Posts: 5
Location: Cleveland, OH
Hi,
When defining a class, I'm defining properties and specifying the sql-type. eg:

Code:
<property name="AString" type="String">
    <column name="ASTRING" not-null="false" unique="false"
                 sql-type="VARCHAR2(32)"/>
</property>


Is there a way from IType (or via some other class in the metadata) that I can access the value specified in the "sql-type" attribute at runtime? What I'm ultimately trying to do is use the nhib metadata to determine the field length (and scale/precision for decimal types). Any help would be most appreciated.

thanks,
--john


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 01, 2007 9:28 pm 
Newbie

Joined: Wed Oct 26, 2005 5:28 am
Posts: 7
Location: Australia
Hi there John,

I have just come up against the same problem and was wondering if you had discovered a solution?


Cheers,

Brad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 01, 2007 9:37 pm 
Newbie

Joined: Mon Jan 01, 2007 6:18 pm
Posts: 11
Location: New Zealand
You guys could look at not using .hbm.xml files and making the mappings in your source code with the nhibernate.mapping.attributes library. If you did this you may be able to (not sure on this) use reflection to view the sql type.

It might also be possible for you to use reflection on the .hbm.xml (embeded resource)

I would recommend searching google for something like: tutorial reflection c# embeded resource

Hope this helps. I am not sure if nhibernate has a mechanism for this? perhaps this is a feature that could be implemented?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 01, 2007 9:46 pm 
Newbie

Joined: Wed Oct 26, 2005 5:28 am
Posts: 7
Location: Australia
Hi rhwilburn, thanks for the quick reply.

Yeah, I'm not sure either. You can access some mapping metadata at runtime by calling GetClassMetadata on ISessionFactory, but unfortunately I couldn't find anything related to field length there.

Thanks for the suggestions. I will do a search this afternoon and see if I can find anything.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 8:02 am 
Newbie

Joined: Sat Sep 02, 2006 7:27 am
Posts: 5
Location: Cleveland, OH
Hi Brad,
No, I never did. I navigated pretty far into the internal structures and could never find where this is. This one is a bit aggrevating to me. Knowing the field lengths of strings is usually important to know for UI constructing and field validations. So I don't know why this field wouldn't be readily accessable or why it's such a secret. It has been asked in a number of posts and it never gets answered.

Please let me know if you find an answer. This one is getting back on the front burner for me in about a week or so. My plan was to study the source of the SQL schema generator and find out where it gets the information. If that doesn't work, our plan is to generate a aux xml metadata file that contains addtioinal information that is hard to get from nhib. We're using the andromda code generator which generates the hbm.xml files and C# source using a UML model.

cheers,
--john


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 9:10 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
IClassMetadata.GetPropertyType("PropertyName").SqlTypes(sessionFactory).Length;

GetPropertyType returns an IType which describes a property type. SqlTypes(sessionFactory) returns an array of SqlType objects which correspond to individual column types (a property may be stored into more than one column).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 5:36 pm 
Newbie

Joined: Wed Oct 26, 2005 5:28 am
Posts: 7
Location: Australia
Thanks Sergey, it's much appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.