-->
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.  [ 9 posts ] 
Author Message
 Post subject: Float Mapping-Type?
PostPosted: Sun Jan 08, 2006 2:30 pm 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Hi there,

i am really new to nHibernate. And i am asking myself how can i map a float? In the documentation there is no defined nHibernate Type for float?

Greetings

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 12:02 am 
Newbie

Joined: Sat Dec 24, 2005 8:39 am
Posts: 15
Hi

I guess hibernate would map it to an appropriate type if you do not explicitly specify a type in the mapping file. I am also new to using Hibernate but for timebeing you can do this so that you can continue with your work.

Regards
Ahmad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 5:31 am 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Right now i am mapping to an double. I was just wondering if there is no built-in float type?

Thx anyway :-)

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 7:39 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, there is, called Single (or System.Single because that's the "real" name of float in .NET runtime). Or you can just leave out the type attribute and NH will determine the type itself.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 9:31 am 
Newbie

Joined: Sat Dec 24, 2005 8:39 am
Posts: 15
Hi Sergey


Can you please let me know what the type would be for boolean and long type of attributes in the mapping file

Regards
Ahmad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 10:23 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
http://www.hibernate.org/hib_docs/nhibernate/html/basic-mapping.html#mapping-types


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 10:44 am 
Newbie

Joined: Sat Dec 24, 2005 8:39 am
Posts: 15
Thanks Sergey,

That link was really helpful.

Regards
Ahmad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 09, 2006 11:13 am 
Newbie

Joined: Sat Dec 24, 2005 8:39 am
Posts: 15
Sergey,

The link is quite informative, and i tried using YesNo in my mapping file

Following is a property from my mapping file

Quote:
<property name="maleOrFemale" type="YesNo">
<column name="IS_MALE" />
</property>


Following are getter / setter of the maleOrFemale attribute in the domain class
Code:
                private boolean maleOrFemale;

   public boolean isMaleOrFemale() {
      return maleOrFemale;

   }
   
   public void setMaleOrFemale(boolean maleOrFemale) {
      this.maleOrFemale = maleOrFemale;
   }



Following is the code I wrote to execute list() of the query object to retrieve a list
Code:

    Session objSession = MyHibernateUtil.currentSession();
    strQuery = " from Person ";
    objQuery = objSession.createQuery(strQuery);
    listPeople = objQuery.list();



Exception is as follows :
Code:
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: YesNo, for columns: [org.hibernate.mapping.Column(IS_MALE)]
java.lang.ExceptionInInitializerError
   at src.MyHibernateUtil.<clinit>(MyHibernateUtil.java:16)
   at src.ManageOrders.listFamilies(ManageOrders.java:193)
   at src.TestHibernate.main(TestHibernate.java:154)
Caused by: org.hibernate.MappingException: Could not determine type for: YesNo, for columns: [org.hibernate.mapping.Column(IS_MALE)]
   at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:265)
   at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:252)
   at org.hibernate.mapping.Property.isValid(Property.java:174)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:325)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:188)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:839)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1000)
   at src.MyHibernateUtil.<clinit>(MyHibernateUtil.java:12)
   ... 2 more
Exception in thread "main"


Thanks
Ahmad


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 12:48 am 
Newbie

Joined: Sat Dec 24, 2005 8:39 am
Posts: 15
Hi Sergey,

using yes_no type or true_false worked. Thanks, I realized while I was going through http://www.hibernate.org/hib_docs/api/n ... oType.html.

THANKS A LOT SERGEY!!!!

Regards
Ahmad


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