Reputation: 149
I have a property called isActive in my pojo class. When I generated the accessors for this property using Eclipse IDE, it generates following getters and setters
Getter : isActive()
Setter : setActive()
However, when I try to write this property using ibatis framework by mentioning property name as "isActive" , it cribs about not able to find any WRITEABLE propery named 'isActive'. The problem I think lies with not able to deduce the correct property name by inferring setter as setIsActive().
What is the best way to go about this without changing the property name or getter ?
Upvotes: 8
Views: 28349
Reputation: 14558
primitive boolean field getters are created as isFieldName
. So in Ibatis you should give the property name as active
not isActive
Upvotes: 12
Reputation: 149
Thanks for the responses. Going by the requirements I had that I didn't wish to change my pojo class member variables, ibatis version that I was using wasn't working as expected. When I upgraded my version to 2.3.4 from 2.3.0 , the issue was resolved and same code worked seamlessly. I assume with this upgrade, they factored in the java beans convention of generating isActive() and setIsActive() accessors if property of type boolean primitive is defined as isActive. Thanks !
Upvotes: 0
Reputation: 18445
The pojo naming convention expects boolean
types called xxx
to have methods isXxx
and setXxx
.
In your case your pojo should look like;
public class MyPojo
{
private boolean active;
public boolean isActive()
{
return active;
}
public void setActive(boolean active)
{
this.active = active;
}
}
You can demonstrate this yourself by creating a class in your IDE and defining the private boolean active
variable, and then getting the IDE to generate getters and setters.
Upvotes: 5
Reputation: 1612
I have not used iBatis, but Hibernate allows you to specify the access method name. This is where you can override the default behavior of ORMs to compute method name for setting property.
Upvotes: 0
Reputation: 114787
There's a way out.
Visit Windows -> Preferences -> Java -> Code Style and deselect the "Use 'is' prefix..." property (of course you can change this on project properties if you don't want this as a global behaviour in eclipse).
This will change the behaviour to
Getter : getIsActive()
Setter : setIsActive()
Ugly to my eyes but ibatis should stop complaining now.
Upvotes: 0