data not persisted using hibernate spring integration

Hi All,

I am trying to integrate vaadin with hibernate and spring. I am trying to persiste the data and at a same time trying to display it in table. But at run time, table doesn’t show any record.When I check the Db table, there also I am not able to find any record. But I am not getting any error also in console. Please help me to solve the issue.

Following are the related code Snippets.


Domain class user

@Entity
@Table(name = "user")
public class User implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = 8496087166198616020L;
	private String userId;
	private String userName;
	private Integer age;
	private Boolean registered;

	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(name = "userId")
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	@Column(name = "userName", nullable=false)
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	@Column(name = "age")
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}
	@Column(name = "registered", nullable=false)
	public Boolean getRegistered() {
		return registered;
	}

	public void setRegistered(Boolean registered) {
		this.registered = registered;
	}
}


DaoImpl class

@Repository("userDao")
@Transactional
public class UserDaoImpl implements UserDao {
	private HibernateTemplate hibernateTemplate;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {		
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}

	@Transactional
	public void saveUser(User user) {
		hibernateTemplate.saveOrUpdate(user);		
	}

	//@Transactional
	public void deleteUser(User user) {
		System.out.println("delete is called********************");
		hibernateTemplate.delete(user);

	}

	@SuppressWarnings("unchecked")
	public List<User> getAllUser(User user) {
		return (List<User>) hibernateTemplate.find("from "
				+ User.class.getName());
	}

	public User selectUserById(String userId) {
		return hibernateTemplate.get(User.class, userId);
	}

}


Spring config. file(applicationContext class)

<?xml version="1.0" encoding="UTF-8"?>




org.gjt.mm.mysql.Driver


jdbc:mysql://localhost:3306/HR


root


mysql123


<context:component-scan base-package=“com.example.vaadinspring” />







org.hibernate.dialect.MySQL5InnoDBDialect
create
true










<tx:annotation-driven />


Vaadin main class

@Override
	public void init() {
		Window mainWindow = new Window("Vaadinspring Application");
		Label label = new Label("Hello Vaadin user");
		mainWindow.addComponent(label);
	    SpringContextHelper helper = new SpringContextHelper();
		UserDao bean = (UserDao) helper.getBean("myUserDao");
		User user = new User();  
		user.setAge(28);  
		user.setUserName("Vikram");  
		user.setRegistered(true);
		bean.saveUser(user); 		
		UserTable uTable=new UserTable(this);
		mainWindow.addComponent(uTable);
		setMainWindow(mainWindow);
}


User Table class

@SuppressWarnings("serial")
public class UserTable extends Table {
	
	public UserTable(){
		
	}
	List<User> myUserList; 
	private UserDao myUserListBean;
	
	public UserDao getMyUserListBean() {
		return myUserListBean;
	}

	public void setMyUserListBean(UserDao myUserListBean) {
		System.out.println("I am here, bean=" + myUserListBean);
		this.myUserListBean = myUserListBean;
	}

	public List<User> getMyUserList() {
		return myUserList;
	}

	public void setMyUserList(List<User> myUserList) {
		this.myUserList = myUserList;
	}

	public UserTable(VaadinspringApplication app){
		setSizeFull();	
		SpringContextHelper helper = new SpringContextHelper();
		myUserListBean = (UserDao) helper.getBean("myUserDao");
		myUserList = myUserListBean.getAllUser(new User());
		BeanItemContainer<User> container = new BeanItemContainer<User>(User.class);
		for (User o : myUserList) {
			container.addBean(o);
		}
		this.setContainerDataSource(container);
	}

}

Please provide some input to solve this issue.I am using hibernate version 3.6.0 and Spring version 3.0.4 and MySQL as Database.

Regards,
Vikram

hurray…I have found it…

commenting out create in spring config. file have done the thing for me.

Vikram