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: Recovery of the types of columns of the database
PostPosted: Thu Jul 19, 2007 3:11 pm 
Newbie

Joined: Thu Jul 12, 2007 1:35 pm
Posts: 9
Hello, I try To recover the type of a column for example the identifier, I used the IClassmetadata interface where I have to recover the type of the identifier (IdentifierType) and his type SQl (SqlTypes) which must need the NHibernate.Engine.IMapping interface, I do not know much a thing about this Interface(IMapping )...!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 6:19 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
I'm not sure if there's another way, but to get at entity mapping metadata, we hold on to the NHibnerate.Cfg.Configuration object that's used to create the session factory, and expose it in our entity service singleton along with the session factory. Then we can do things like this:

Code:
NHibernate.Mapping.PersistentClass persistentClass =
   configuration.GetClassMapping(entityType);

if (persistentClass == null)
{
   throw new NHibernate.MappingException(
      string.Format("Mapping for class '{0}' not found",
         entityType.AssemblyQualifiedName));
}

NHibernate.Mapping.Property idProperty = persistentClass.IdentifierProperty;

NHibernate.Mapping.Column idColumn = null;
foreach (NHibernate.Mapping.Column column in idProperty.ColumnCollection)
{
   // we assume here that the identifier property
   // is backed by one column
   idColumn = column;
   break;
}


From there you can get all kinds of information on mapped properties and the columns that back them.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 21, 2007 10:50 am 
Newbie

Joined: Thu Jul 12, 2007 1:35 pm
Posts: 9
I thank you for your assistance, I succeeded in finding the solution to recover the size of the columns specified in the file mapping thanks to your code.


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.