hibernate - Java hashmap mapping in database -


my entity class

@entity public class student_enroll implements serializable { private static final long serialversionuid = 1l;  @id @generatedvalue(strategy = generationtype.auto) private long id;  private int level_num; private int term; private string student_session; private hashmap<string,integer>mark_value;  @onetoone private student student;  public string getstudent_session() {     return student_session; }  public void setstudent_session(string student_session) {     this.student_session = student_session; }    public int getlevel_num() {     return level_num; }  public void setlevel_num(int level_num) {     this.level_num = level_num; }  public int getterm() {     return term; }  public void setterm(int term) {     this.term = term; }  public student getstudent() {     return student; }  public void setstudent(student student) {     this.student = student; }  public hashmap<string, integer> getmark_value() {     return mark_value; }  public void setmark_value(hashmap<string, integer> mark_value) {     this.mark_value = mark_value; }  public long getid() {     return id; }  public void setid(long id) {     this.id = id; }  @override public int hashcode() {     int hash = 0;     hash += (id != null ? id.hashcode() : 0);     return hash; }  @override public boolean equals(object object) {     // todo: warning - method won't work in case id fields not set     if (!(object instanceof student_enroll)) {         return false;     }     student_enroll other = (student_enroll) object;     if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {         return false;     }     return true; }  @override public string tostring() {     return "com.domain.student_enroll[ id=" + id + " ]"; }  } 

and controller function

   @requestmapping(value="/add_mark",method = requestmethod.post)    public void add_mark(httpservletrequest req){     hashmap<string,integer>map=new hashmap<string,integer>();     int level=integer.parseint(req.getparameter("level"));     int term=integer.parseint(req.getparameter("term"));     student_enroll enroll=student_service.get_student_enroll(level, term);     list<course>list_course=course_service.list_course(level, term);     iterator<course>itr=list_course.iterator();      while(itr.hasnext()){        enroll.put(itr.next().getcourse_code(),75);     }      enroll.setmark_value(map); // set hashmap      student_service.update_student_enroll(enroll); } 

i want set hashmap using sethashmap() , want persist entity in database.is appropriate way cause when want persist other attribute of entity persisted hashmap attribute contains blob object.

how persist hashmap of primitive type?

jpa supports map persistencse using @mapkey, @mapkeyjoincolumn ... annotations refer following article details:

http://en.wikibooks.org/wiki/java_persistence/relationships#maps


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -