I have the book "Hibernate in Action". I finally got hibernate configured to work but now my understanding from the book differs from what I see happening when I run the application. I thought that when I created a new User object that it would be persisted without me having to call session.save(user) because these columns are specified in file User.hbm.xml. I noticed that when I call session.save(user) it saves a row in the Users table. If I don't call it then then that table has 0 rows. I should note that I have the following in my configuration...
Code:
cfg.setProperty("hibernate.hbm2ddl.auto", "create");
Hibernate version: 3.0
Mapping documents:User.hbm.xml:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.business.service.hib3">
<class name="User" table="USERS">
<id name="id" column="USER_ID">
<generator class="native"/>
</id>
<property name="username" column="USERNAME"/>
<property name="password" column="PASSWORD"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): Session session = sessions.openSession();
Transaction tx = session.beginTransaction();
User user = new User();
user.setUsername(username);
user.setPassword(password);
//session.save(user); // why do I need this???
tx.commit();
session.close();
Full stack trace of any exception that occurs:None
Name and version of the database you are using:My SQL 4.1.9
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code: