-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Console printed "Insert" statement,but no data was inserted
PostPosted: Mon Mar 15, 2010 8:10 am 
Newbie

Joined: Mon Mar 15, 2010 7:57 am
Posts: 2
this is my UserDAO
Code:
   package org.innolab.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.innolab.entity.User;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;



public class UserDAO extends HibernateDaoSupport {
   private static final Log log = LogFactory.getLog(UserDAO.class);



   public void save(User transientInstance) {
      log.debug("saving User instance");
      try {
         getHibernateTemplate().save(transientInstance);
         log.debug("save successful");
      } catch (RuntimeException re) {
         log.error("save failed", re);
         throw re;
      }
   }
}


and here is my UserServiceImpl

Code:
package org.innolab.service.impl;

import java.util.List;

import org.innolab.dao.UserDAO;
import org.innolab.entity.User;
import org.innolab.service.UserService;




public class UserServiceImpl implements UserService {
   public UserDAO userDAO;
   public void saveUser(User user) {
      this.userDAO.save(user);
   }

}



and here is my UserActioncode

Code:
         User user = new User(username, password, email);
            userService.saveUser(user);


and here is my User entity

Code:
package org.innolab.entity;

import java.util.HashSet;
import java.util.Set;

/**
* User entity. @author MyEclipse Persistence Tools
*/

public class User implements java.io.Serializable {

   // Fields

   private Integer id;
   private String name;
   private String password;
   private String email;
   private String photo;
   private Set blogs = new HashSet(0);

   // Constructors

   /** default constructor */
   public User() {
   }

   /** minimal constructor */
   public User(String name, String password, String email) {
      this.name = name;
      this.password = password;
      this.email = email;
   }

   /** full constructor */
   public User(String name, String password, String email, String photo,
         Set blogs) {
      this.name = name;
      this.password = password;
      this.email = email;
      this.photo = photo;
      this.blogs = blogs;
   }

   // Property accessors

   public Integer getId() {
      return this.id;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   public String getName() {
      return this.name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getPassword() {
      return this.password;
   }

   public void setPassword(String password) {
      this.password = password;
   }

   public String getEmail() {
      return this.email;
   }

   public void setEmail(String email) {
      this.email = email;
   }

   public String getPhoto() {
      return this.photo;
   }

   public void setPhoto(String photo) {
      this.photo = photo;
   }

   public Set getBlogs() {
      return this.blogs;
   }

   public void setBlogs(Set blogs) {
      this.blogs = blogs;
   }

}


and here is my console

Code:
Hibernate: select user0_.id as id0_, user0_.name as name0_, user0_.password as password0_, user0_.email as email0_, user0_.photo as photo0_ from innolab.user user0_ where user0_.name=?
Hibernate: insert into innolab.user (name, password, email, photo) values (?, ?, ?, ?)


can anbody help me out with this ? thanks


Top
 Profile  
 
 Post subject: Re: Console printed "Insert" statement,but no data was inserted
PostPosted: Mon Mar 15, 2010 8:34 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi,

it could be that:
- you not commited yet the transaction in your application.
- you connect then to your database with a isolation level which is READ_COMMITED or higher,
then by quering you cannot 'see' the newly inserted data (although phisically already present on the database).


Top
 Profile  
 
 Post subject: Re: Console printed "Insert" statement,but no data was inserted
PostPosted: Mon Mar 15, 2010 8:56 am 
Newbie

Joined: Mon Mar 15, 2010 7:57 am
Posts: 2
I've added

<property name="hibernate.connection.autocommit">true</property>
to my hibernate configuration file , and I've solved my problem thanks....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.