-->
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: Is this a Bug in Hibernate?
PostPosted: Wed Jul 16, 2008 4:21 am 
Newbie

Joined: Wed Dec 19, 2007 6:49 am
Posts: 8
Location: London
I have a simple class mapped to a sinple table, in that class I have an int value which is mapped to an int value in the MySQL database -
Code:
private int next;

public int getNext() {
     return next;
}

public void setNext(int next) {
    this.next = next;
}


I want next to be a boolean, but because MySQL doesn't support boolean data types it is a TINY_INT 1 or 0. I introduce boolean methods to my class to mask the MySQL boolean issue.

My class now looks like this

Code:
private int next;

public int getNext() {
     return next;
}

public void setNext(int next) {
    this.next = next;
}

public boolean isNext() {
        return next != 0 ;
}

public void setNext(boolean next) {
       if(next) this.next = 1;
       else this.next = 0;
}


When hibernate loads up an object of this class I get -

BasicPropertyAccessor - expected type: boolean, actual value java.lang.Integer
.....
....
IllegalArgumentException: argument type mismatch

..... etc..


Why doesn't Hibernate pick up the setNext(int next) method?

John.


Top
 Profile  
 
 Post subject: Re: Is this a Bug in Hibernate?
PostPosted: Wed Jul 16, 2008 11:33 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
because probably it uses the reflection API and it picks the integer method first. My question is why you have the integer in the first place? Boolean itself should do the work for you. Hibernate mysql dialect will take care of the conversion.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 18, 2008 2:03 pm 
Newbie

Joined: Wed Dec 07, 2005 4:32 pm
Posts: 5
Hi johnhunsley.

I have mapped my boolean attributes with byte in MySQL. And rarely I use native attributes.

Best regards


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.