Announcement Announcement Module
No announcement yet.
Save is not performing in Spring Mvc 3 Hibernate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Save is not performing in Spring Mvc 3 Hibernate

    Dispatcher Servlet is :

    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="${database.driver}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.user}" />
    <property name="password" value="${database.password}" />
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
    <property name="hibernateProperties">
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>

    <bean id="hibernateTransactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
    <bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass"
    value="org.springframework.web.servlet.view.JstlVi ew" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />

    Article Java Class:

    mport javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    import javax.persistence.Temporal;

    @Table(name = "imei")
    public class Article {
    @Column(name = "imei1",nullable = false)
    private Integer imeiNo;
    @Column(name = "date_added")
    private Date addedDate;

    public Article() {
    public Integer getimei1() {
    return imeiNo;

    public void setimei1(Long imei1) {
    this.imeiNo = imeiNo;

    public Date getAddedDate() {
    return addedDate;

    public void setAddedDate(Date addedDate) {
    this.addedDate = addedDate;

    Article Controller :

    public class ArticleController {

    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 :
    public interface ArticleService {

    public void addArticle(Article article);

    public List<Article> listArticles();

    Article ServiceImpl:

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public class ArticleServiceImpl implements ArticleService {

    private ArticleDao articleDao;

    public ArticleServiceImpl() {

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    public void addArticle(Article article) {

    public List<Article> listArticles() {
    return articleDao.listArticles();

    This Error comes when saving data,(But no error while displaying data)


    org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is ids for this class must be manually assigned before calling save(): net.devmanuals.model.Article

    root cause ids for this class must be manually assigned before calling save(): net.devmanuals.model.Article

  • #2
    From your Entity class:
    @Table(name = "imei")
    public class Article {
    @Column(name = "imei1",nullable = false)
    private Integer imeiNo;
    You have indicate @Id and this means, you MUST need to generate unique ID manually by your application and assign to "artical" instance and then perform the "save()" operation.

    If you indented framework to generate automatically the unique ID for you, then you MUST use the following.

    @GeneratedValue (strategy = GenerationType.AUTO)


    • #3
      Thanks Sir actually i want to enter values manually id also, and i did it also, it was my fault actually in article class i was writing wrong setter method. I correct it , now works fine,,

      But Please tell me that how to enter value in two tables at one time?? because i have to enter imei number in one table and imei and date and time in second table. i have perform working of second table but i didnt know how to enter values at one time in two tables. Pleae help if you can
      Last edited by pankaj369; May 19th, 2013, 12:11 PM.


      • #4
        Help me friends..