Problem
I would like to be able to fetch the length of a property from the hibernate mapping information. I have found other entries in this forum stating that I shall use SqlTypes() method from iType. But the problem is that when I do that I always get a SqlType defintion with length set to 0. I have tried varius ways of setting the length attribute - both in the property tag and also as shown below in the column part of a mapping. In all cases I get a SqlType object with Length = 0 and LengthDefined = false.
Can anybody guide in the right direction for retrieving this form for metadata or simply indicate what I am doing wrong.
Thanks in advance.
Hibernate version: NHibernate 1.2.1
Mapping documents:
Code:
<class name="TypeCatalog, Mimer.Data" table="CAT_TYPE_TB" lazy="false" >
<id name="OID" column="OID" type="string">
<generator class="assigned" />
</id>
<version name="Version" column="VERSION" unsaved-value="-1"/>
<property name="Type" type="string" >
<column name="TYPE_VALUE" not-null="true" sql-type="VARCHAR2(100)" length="100" />
</property>
</class>
Code used to fetch length information:Code:
public int GetPropertyLength(PropertyInfo info) {
int length = 20;
IClassMetadata metaData = DataAccessHttpModule.CurrentFactory.GetClassMetadata(info.ReflectedType);
IType type = metaData.GetPropertyType(info.Name);
if (type != null) {
SqlType[] sqlTypes = type.SqlTypes((IMapping)DataAccessHttpModule.CurrentFactory);
if( sqlTypes[0].LengthDefined ) {
length = sqlTypes[0].Length;
} else {
// TODO log an error
}
} else {
// TODO log an error
}
return length;
}
Name and version of the database you are using: Oracle 9