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