I think I may have found a bug with the way Hibernate looks to do reflection of method names. The below code snippets define my entity mapping in the abstract class then overrides the function names for alternate use in the concrete class. Running the code results in an IllegalArgumentException saying expected boolean, but got Byte. It appears hibernate is not looking through all available methods with the same name, but just picking the first (or an arbitrary ) one when doing the reflection. I have a work around by just renaming the methods dealing with the Byte to getEnabledByte/setEnabledByte. I have not looked at the source, but thought I'd pass this on to others who have more time to investigate.
From AbstractUserdata.java (Generated)
Code:
@Column( name = "enabled", unique = false, nullable = false )
public Byte getEnabled()
{
return this.enabled;
}
public void setEnabled( Byte enabled )
{
this.enabled = enabled;
}
I have an interface, UserData
Code:
public boolean isEnabled();
public void setEnabled( boolean enabledValue );
finally in my entity Userdata.java I implement the interface
Code:
@Entity
@Table(name = "userdata", catalog = "xxxxx")
public class Userdata extends AbstractUserdata implements UserData
{
....
@Transient
public boolean isEnabled()
{
if ( getEnabledByte() == ( byte ) 1 )
return true;
else
return false;
}
@Transient
public void setEnabled( boolean enabledValue )
{
if ( enabledValue )
setEnabledByte( ( byte ) 1 );
else
setEnabledByte( ( byte ) 0 );
}
}