I have an entity .
@Entity
@Table(name = "TABLE_NAME")
public class someName implements Serializable{
....
...
@ManyToOne
@JoinColumn(name="some", referencedColumnName="some_ID", updatable = false)
private Data data;
//corresponding getter and setter
public Data getData() {
return data;
}
public void setDataTYPE(Data data) { //this name is not in proper format
this.data = data;
}
}
Now when i do getData on this entity object, I get a null pointer exception although the object is not null. Code that generated the null pointer
if(someNameOBJ==null){
//Do something
}else{
sysout(someNameOBJ.getData.getId);// It generates NPE
}
But when i changed my getter/setter to proper format (generate it from eclipse), the null pointer is gone.
public Data getData() {
return data;
}
public void setData(Data data) { //this name is in proper format
this.data = data;
}
Why is the null pointer gone in this case? Does naming of getter/setter should be in proper format? If so why? I am aware of Java bean naming conventions, but what difference does a function name makes. (As I am always concerned about what a function does rather then what its name is). I am using hibernate and spring 3, java 1.6. I think it is a hibernate issue and something to do with reflection. Help me to find the root