java - Save is not performing in Spring Mvc 3Hibernate -


article class:

package net.devmanuals.model; import java.util.date; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.id; import javax.persistence.table; import javax.persistence.temporal;      @entity     @table(name = "imei")     public class article {     @id         @column(name = "imei1",nullable = false)     private long imeino;         @column(name = "date_added")     @temporal(javax.persistence.temporaltype.date)     private date addeddate;      public article() {           }          public long getimei1() {         return imeino;     }      public void setimei1(long imei1) {         this.imeino = imeino;     }          public date getaddeddate() {         return addeddate;     }      public void setaddeddate(date addeddate) {         this.addeddate = addeddate;     }    } 

articlecontroller class:

package net.devmanuals.controller;  import java.util.hashmap; import java.util.map;  import net.devmanuals.model.article; import net.devmanuals.service.articleservice;  import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.validation.bindingresult; import org.springframework.web.bind.annotation.modelattribute; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.servlet.modelandview;  @controller @requestmapping("/articles") public class articlecontroller {      @autowired     private articleservice articleservice;      @requestmapping(value = "/save", method = requestmethod.post)     public modelandview savearticle(@modelattribute(" article") article  article,             bindingresult result) {          articleservice.addarticle( article);         return new modelandview("redirect:/articles.html");     }      @requestmapping(method = requestmethod.get)     public modelandview listarticles() {      map<string, object> model = new hashmap<string, object>();         model.put("articles",  articleservice.listarticles());          return new modelandview("articleslist", model);     }      @requestmapping(value = "/add", method = requestmethod.get)     public modelandview addarticle(@modelattribute("article") article article,             bindingresult result) {         return new modelandview("addarticle");     }  } 

article service:

package net.devmanuals.service;  import java.util.list;  import net.devmanuals.model.article;  public interface articleservice {      public void addarticle(article article);      public list<article> listarticles(); } 

this error comes when saving data,(but no error while displaying data):

exception org.springframework.web.util.nestedservletexception: request processing failed; nested  exception org.hibernate.id.identifiergenerationexception: ids class must manually assigned before calling save(): net.devmanuals.model.article     root cause  org.hibernate.id.identifiergenerationexception: ids class must manually assigned before calling save(): net.devmanuals.model.article 

the exception says all. must assign id entity before persisting it. call method sets value of imeino before calling persist(). unfortunately, don't have such method. 1 looks such setter following one:

public void setimei1(long imei1) {     this.imeino = imeino; } 

but, not badly named (it should called setimeino), has obvious bug: ignores argument, , sets value of imeino value has.

given mess getters , setters are, advice be:

  • remove them all
  • use ide regenerate them automatically

the setter should be:

public void setimeino(long imeino) {     this.imeino = imeino; } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -