-->
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.  [ 1 post ] 
Author Message
 Post subject: Get vs Is
PostPosted: Tue Oct 08, 2013 7:24 am 
Newbie

Joined: Tue Oct 08, 2013 7:10 am
Posts: 1
I had a class that implemented both isValue and getValue methods and hibernate seemed to randomly choose which one to use. Here's what the property from my mapping file looks like:

Code:
<property generated="never" lazy="false" name="executed" type="java.lang.Integer">
   <column name="Executed">
   </column>
</property>


Mapping to the following Java class:

Code:
public class Test
{
   private int executed;

   public Test()
   {
   }
   
   public Integer getExecuted()
   {
      return executed;
   }

   public boolean isExecuted()
   {
      return executed == 1;
   }

   public void setExecuted(Integer executed)
   {
      this.executed = executed;
   }
}

I know this shouldn't be done, but sometimes stuff like this finds it's way in to the code when a few people get their hands on a class.

Every so often Hibernate would throw a Boolean to Integer class cast exception. My question is how does hibernate choose what to use as a getter in this case? For me it seemed to choose based on the state of the system it was running on, I recently re-installed windows on an SSD and was finally getting it every time I ran the class, before that I would get the class cast exception once out of every 10 or so runs. It took me a long time to track down this bug because I couldn't reliably reproduce it until recently.

Thanks for the help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.