can i have a method in entity class without Mapping to the database
I am using Hibernate to map with MySQL
I have an entity class in which I have the methods mapped with columns in MySQL
The question is, if its possible that I do not map some of the method in that class with any column in SQL, as if i try not to map one of my method in entity cl开发者_开发知识库ass, it gives exception.
Here is the code snippet , what i am trying
@Column(name="skills")
public String getSkills() {
return skills;
}
public void setSkills(String skills) {
this.skills = skills;
}
@Transient
public int getRowCount() {
return rowCount;
}
public void setRowCount(int count) {
this.rowCount = count;
}
I have used @transiet , but after this if i set some value in setRowCunt and then tries to get that same value with getRowCount it gives null value , anyone have some idea
thanks
You are correct with the @Transient annotation. Perhaps you are setting the rowCount value in one object, than fetch it from db and try to get the value from it? - it would obviously fail because the field is not persisted and you're dealing with new instance of that object.
Perhaps You could provide broader context - what are the steps between setting a value and getting null?
精彩评论