-->
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.  [ 1 post ] 
Author Message
 Post subject: AnnotationConfiguration, could not save/update data
PostPosted: Fri Jun 11, 2010 12:03 am 
Newbie

Joined: Mon Dec 14, 2009 5:38 am
Posts: 13
Hello,
I created a DAO class like this:

Code:
public class UserDAO {
  private Session sess;
  public UserDAO() {
    AnnotationConfiguration ac = new AnnotationConfiguration();
    ac.addAnnotatedClass(User.class);
    sess = ac.configure().openSession();
  }
 
  public void saveOrUpdate(User user, String name) {
    user.setName(name);
    sess.saveOrUpdate(user);
  }

  public List<?> findAll() {
    return sess.createQuery("from User").list();
  }
}


if I run the line below, it works. it returns the number of rows inside "user" table.
Code:
System.out.println("Records: " + new UserDAO().findAll().size());


but when I execute this line, it doesn't work. it doesn't add the admin user to the table.
Code:
new UserDAO().saveOrUpdate(new User(), "Admin");


btw, I don't put <mapping class="com....User"/> into the hibernate.cfg.xml, in hoping that the code above
will load it dynamically.

could someone give me suggestion?

thanks


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

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.