-->
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.  [ 2 posts ] 
Author Message
 Post subject: mapping System.Type as a property, to a string column
PostPosted: Sun Sep 30, 2007 9:44 pm 
Newbie

Joined: Fri Aug 03, 2007 4:44 pm
Posts: 6
Has anyone been able to map a property of type "System.Type" to a database column of a string type, and do searches against it?

Specifically, i'm using SQLite and a Text column. This is the class / mapping that I have:

... class
public class MyObject
{
private Type _objectType;
public Type ObjectType
{
get { return _objectType; }
set { _objectType = value; }
}
}

... mapping
<property name="ObjectType" type="System.Type" />

when I try to do searches against this specific column, I constantly get an Object reference error:

NHibernate.Util.ADOExceptionReporter - Object reference not set to an instance of an object.

NHibernate.ADOException: could not execute query
[ SELECT this_.Id as Id32_0_, this_.MessageType as MessageT2_32_0_, this_.Message as Message32_0_, this_.Status as Status32_0_, this_.ObjectId as ObjectId32_0_, this_.ObjectType as ObjectType32_0_ FROM Messages this_ WHERE this_.ObjectType = ? ]
Positional parameters: 0 null

... it seems that i always end up with a null parameter... i've tried implementing a custom IUserType and I end up with the same thing. Ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 30, 2007 11:12 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Get rid of the 'type' atribute in this:
Code:
<property name="ObjectType" type="System.Type" />

and let NHibernate deal with it. It will write the fully qualified type name (MyAssembly.MyNamespace.MyObject,MyAssembly) as a string column (nvarchar) and then will do the conversion in your biz object for you when it is hydrated/persisted.
Mike

_________________
If this helped...please remember to rate it!


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