Hi there,
I know this topic is in the FAQ, but I still can't figure out what I am missing. If I want to do anything with the DB I seem to have to use a Transaction around the code. If I don't do it, no data is saved in the DB.
TIA chris
Hibernate version: 2.1.2
Mapping documents:
Code:
<hibernate-mapping package="com.schluer.schluerdb.model">
<class name="LeadPerson" table="LeadPerson">
<id name="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="department"/>
<many-to-one name="rank"/>
<many-to-one name="sex"/>
<property name="title" type="string"/>
<property name="forename" type="string"/>
<property name="surename" type="string"/>
<set name="contactData" cascade="delete">
<key column="leadPersonID"/>
<one-to-many class="Contact"/>
</set>
<set name="acceptedNewsletters" cascade="delete">
<key column="leadPersonId"/>
<many-to-many column="newsletterId" class="Newsletter"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Session sess = HibernateUtil.currentSession();
LeadPerson p = new LeadPerson();
p.setSurename("Tester");
p.setForename("Test");
sess.save(p);
sess.flush();
HibernateUtil.closeSession();
Full stack trace of any exception that occurs: none
Name and version of the database you are using: PostgreSQL 7.4.1 with JDBC3 driver.
Debug level Hibernate log excerpt:Code:
12:51:14,951 INFO QueryCache:39 - starting query cache at region: net.sf.hibernate.cache.QueryCache
12:51:15,072 DEBUG SQL:237 - select nextval ('hibernate_sequence')
12:51:15,122 DEBUG SQL:237 - insert into LeadPerson (department, rank, sex, title, forename, surename, id) values (?, ?, ?, ?, ?, ?, ?)
12:51:15,132 DEBUG LongType:41 - binding null to parameter: 1
12:51:15,132 DEBUG LongType:41 - binding null to parameter: 2
12:51:15,132 DEBUG LongType:41 - binding null to parameter: 3
12:51:15,142 DEBUG StringType:41 - binding null to parameter: 4
12:51:15,142 DEBUG StringType:46 - binding 'Test' to parameter: 5
12:51:15,142 DEBUG StringType:46 - binding 'Tester' to parameter: 6
12:51:15,152 DEBUG LongType:46 - binding '152' to parameter: 7