-->
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.  [ 13 posts ] 
Author Message
 Post subject: hbm2java: type 'boolean' generates 'java.lang.Boolean' code
PostPosted: Wed Mar 16, 2005 9:34 am 
Newbie

Joined: Wed Jan 19, 2005 2:39 pm
Posts: 16
Hi There -

I recently updated my hibernate-tools.jar to the one contained in hibernate-extensions-2.1.3:

Now, properties of type 'boolean' in my hbm.xml file result in code generated for 'java.lang.Boolean's.

This, obviously, breaks my application. Does anyone know why it does this? Or how to fix it?

Example:

From the .hbm.xml file:

Code:
    <property
        name="enabled"
        type="boolean"
        column="enabled"
        length="1"
    />


With the older version (2.0.1), this code was generated:

Code:
    public boolean isEnabled() {
        return this.enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }


Now, hibernate-tools.jar from hibernate-extensions-2.1.3 generates this code:

Code:
    public Boolean getEnabled() {
        return this.enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }


Any ideas?

TIA
Mike[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 7:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
hbm2java is now (more) correct since your Property does not define a not null attribute. Since the default is that is it nullable the Boolean object is correct. Define the property a not-null="true" and then generate again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 9:22 pm 
Newbie

Joined: Wed Jan 19, 2005 2:39 pm
Posts: 16
Worked perfectly... and makes sense.

Thanks much.
M.


Top
 Profile  
 
 Post subject: Still fails
PostPosted: Sun Jul 03, 2005 8:02 am 
Newbie

Joined: Wed Nov 24, 2004 1:08 pm
Posts: 5
I tried this too, but I'm still getting java.lang.Boolean rather than just boolean:

<property
name="manager"
type="boolean"
not-null="true"
length="1"
column="manager"/>

I'm using the latest hibernate and hibernate-tools, I just downloaded it yesterday.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 03, 2005 2:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
this is a muddy issue.

in pre 2.1.3 we did not obey the not-null attribute
in 2.1.3 we started obeying tne not-null attribute
in 3 we actually decided to say that the object variant is the best default, but we will provide a way to override the behavior if wanted.


but in 2.1.3 it should do it according to not-null

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:42 pm 
Newbie

Joined: Wed May 25, 2005 11:32 am
Posts: 14
max wrote:
this is a muddy issue.

in pre 2.1.3 we did not obey the not-null attribute
in 2.1.3 we started obeying tne not-null attribute
in 3 we actually decided to say that the object variant is the best default, but we will provide a way to override the behavior if wanted.


but in 2.1.3 it should do it according to not-null



Could you let me how to override this behavior in Hibernate 3????


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 06, 2005 2:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<meta attribute=propert-type>boolean</meta>

later we might add a global toggle

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: HibernateTools-3.1.0.beta1
PostPosted: Thu Nov 10, 2005 6:30 am 
Newbie

Joined: Thu Nov 10, 2005 6:18 am
Posts: 3
max wrote:
> in 3 we actually decided to say that the object variant is the best default, but we will provide a way to override the behavior if wanted.

I try to use 3.1.0.beta1 but get primitive boolean type for nullable columns .
It causes test code to crash on NULL values, what's actually correct for primitive boolean type.

I tried version 3.0 and get Boolean.

later max wrote:
> later we might add a global toggle

Is it done already ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 6:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the rule that I decided to implement is that if you want the primitive types then write the primitive type name and if you want the object type write the object type name.

not-null in the db is not a good default way to choose wether a object property should be nullable or not.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 7:56 am 
Newbie

Joined: Thu Nov 10, 2005 6:18 am
Posts: 3
Wow, it works. There are two examples for other readers:

to get Boolean make:
Code:
<hibernate-reverse-engineering>
  <type-mapping>
     <sql-type jdbc-type="DECIMAL"  precision='1' hibernate-type="Boolean" /> 
  </type-mapping>
  <table-filter match-name="LOG_.*" exclude="true"/>
  <table-filter match-name=".*"/>
</hibernate-reverse-engineering>


to get boolean make:
Code:
<sql-type jdbc-type="DECIMAL"  precision='1' hibernate-type="boolean" />


good job :-)

max wrote:
> not-null in the db is not a good default way to choose wether a object property should be nullable or not

for me a perfect solution sound like this:
1) user should decide what to do with nullable columns , we'd simply add additional attribute nullable="true|false" to sql-type element.
2) if an algorithm decides (by default or user conditions) to make nullable column boolean, we should throw Exception - in most cases such a column in DB contains NULLS and it doesn't not work with boolean.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
#1 suggestion might be a valid request, please add to jira

#2 is not a rule i want to enforce (except maybe throw a warning), and it should check for primtive type, not just boolean - again add to jira

(preferably as two different cases - thanks)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 8:37 am 
Newbie

Joined: Thu Nov 10, 2005 6:18 am
Posts: 3
what a day, i get it compiled and was happy, but it can not run with Hibernate-Version 3.1.rc2:
Quote:
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: Boolean, for columns: [org.hibernate.mapping.Column(TMPPRODUKTBOOL_01)]
Exception in thread "main" java.lang.ExceptionInInitializerError
at tools.HibernateUtil.<clinit>(HibernateUtil.java:22)
at tools.Migrate.main(Migrate.java:18)
Caused by: org.hibernate.MappingException: Could not determine type for: Boolean, for columns: [org.hibernate.mapping.Column(TMPPRODUKTBOOL_01)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:184)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:370)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:975)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1139)
at tools.HibernateUtil.<clinit>(HibernateUtil.java:18)
... 1 more


It sound like v 3.1rc2 do not accept "Boolean" as hibernate-type, seems to be logical. If we'd introduce a new Boolean hibernate-type, so we must to do the same with Integer, Float and so on.

Probably <hbm2hbmxml/> should simply save "boolean" as a hibernate-type in mapping files ?
In any case i replaced it wit sed:

Code:
sed -i.bak s/Boolean/boolean/g *.hbm.xml


and it works after that.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 9:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its called java.lang.Boolean, not just Boolean.

_________________
Max
Don't forget to rate


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