-->
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: Error in mapping file - MSSQL binary type to C#
PostPosted: Thu Jan 19, 2006 6:13 pm 
Newbie

Joined: Thu Jan 19, 2006 5:56 pm
Posts: 4
Hi,

I new using NHibernate. I'm using MyGeneration Tool to generate my classes and .hbm files.

I only have one problem. I have a field, PASSWORD, that is a binary field in MSSQL. I have a mapping exception because of this line:

[NHibernate.MappingException] {NHibernate.MappingException} NHibernate.MappingException

"property mapping has wrong number of columns: TblUti.Model.TblUti type: Object"

StackTrace " at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping)\r\n at NHibernate.Mapping.RootClass.Validate(IMapping mapping)\r\n at NHibernate.Cfg.Configuration.Validate()\r\n at NHibernate.Cfg.Configuration.BuildSessionFactory()\r\n at DAOHibernate.Impl.ConnectionDAO.InitConnectionDAO() in c:\\developpement\\sgc\\daohibernate_cs\\impl\\connectiondao.cs:line 39" string


when running:

_factory = _cfg.BuildSessionFactory();


If I remove the password line from the mapping file, everything is ok.

What am I doing wrong?

Thanks a lot,

Remi




Here is my mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Model.TblUti,Model" table="TBL_UTI">

<id name="Nseq" column="NSEQ" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property column="LOGIN" type="String" name="Login" not-null="true" length="8" />
<property column="PASSWORD" type="object" name="Password" not-null="true" />
<property column="NOM" type="String" name="Nom" not-null="true" length="20" />
<property column="PRENOM" type="String" name="Prenom" not-null="true" length="15" />
<property column="TITRE" type="String" name="Titre" length="30" />
<property column="DOM_DEPT" type="Int32" name="DomDept" not-null="true" />
<property column="DAT_VIGR" type="DateTime" name="DatVigr" not-null="true" />
<property column="DAT_FIN" type="DateTime" name="DatFin" />
<property column="EMAIL" type="String" name="Email" length="150" />
<property column="UTI_CRE" type="Int32" name="UtiCre" />
<property column="DATE_CRE" type="DateTime" name="DateCre" />
<property column="UTI_MODIF" type="Int32" name="UtiModif" />
<property column="DETAIL" type="String" name="Detail" length="256" />
<property column="DATE_MODIF" type="DateTime" name="DateModif" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 11:26 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
I don't think there is a type in NHibernate called "object". You might try "System.Object,System" to use the .NET type.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 11:14 am 
Newbie

Joined: Thu Jan 19, 2006 5:56 pm
Posts: 4
Thanks, but now I have another exception (!)

The line in the mapping file is now:

<property column="PASSWORD" type="System.Object,System" name="Password" not-null="true" />

and I get the following exception:

+ [NHibernate.MappingException] {NHibernate.MappingException} NHibernate.MappingException
"could not interpret type: System.Object,System"

_stackTraceString " at NHibernate.Cfg.Binder.GetTypeFromXML(XmlNode node)\r\n at NHibernate.Cfg.Binder.BindSimpleValue(XmlNode node, SimpleValue model, Boolean isNullable, String path, Mappings mappings)\r\n at NHibernate.Cfg.Binder.PropertiesFromXML(XmlNode node, PersistentClass model, Mappings mappings)\r\n at NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mappings mappings)\r\n at NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model)\r\n at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc)\r\n at NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader)\r\n at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream)\r\n at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering)\r\n at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)\r\n at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)\r\n at NHibernate.Cfg.Configuration.DoConfigure(XmlDocument doc)\r\n at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)\r\n at NHibernate.Cfg.Configuration.Configure(String resource)\r\n at DAOHibernate.Impl.ConnectionDAO.InitConnectionDAO() in c:\\developpement\\sgc\\daohibernate_cs\\impl\\connectiondao.cs:line 34





Do I need to write anything else in my mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 12:06 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What is the type of PASSWORD column of the table? Why are you mapping it to an object?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 12:09 pm 
Newbie

Joined: Thu Jan 19, 2006 5:56 pm
Posts: 4
It's a binary field (encrypted password)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 2:39 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I think the best way would be to declare it as a byte array and use type="Byte[]" (or just let NH determine the type by reflection).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 4:12 pm 
Newbie

Joined: Thu Jan 19, 2006 5:56 pm
Posts: 4
It works fine with Byte[] or with reflexion too.

I will change the default value of the MyGeneration template for Byte[].

Thanks a lot!


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.