1

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

1
  • But, getRowCount returns a primitive integer. How come it gives a null value? May 27, 2011 at 12:14

1 Answer 1

3

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?

4
  • thanks, thing is i dont want to include DB for this rowCount ,as there is no such column there. the purpose is jst to set my own value and then get it from ome where else ,but i am not dealing with the new instance of the object , the steps are candidateResumeInfo.setRowCount(count); return candidateResumeInfo; and then from that class where i am returning this complete objct i use int rowcount = candidateResumeInfo.getRowCount(); am i doing some thing wrong . thanks
    – junaidp
    May 25, 2011 at 10:24
  • if these are the steps described, it should work ok. perhaps you have some middleware that modifies your bean? Have you tried debugging your model object? check if after calling the setRowCount() method rowCount property is updated with proper value. May 25, 2011 at 12:41
  • thanks , yeah i have debugged it , Yes method setrowcount updated after calling ,but in the other class where i use gtrowcount all of the methods have some values(from sql,as they are linked with some columns in sql) but this method is always 0 ,even after setting it from setrowcount.
    – junaidp
    May 28, 2011 at 2:47
  • 1
    ok,its working now ,you were right there was something in middleware that was modifying my bean thanks
    – junaidp
    May 28, 2011 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.