简体   繁体   中英

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 class, 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM