Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.2.6.ga
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.trovare.dal.dto.User" schema="PUBLIC" table="APP_USER">
<id name="id" type="long">
<column name="usr_id"/>
<generator class="native">
<param name="sequence">app_user_usr_id_seq</param>
</generator>
</id>
<property generated="never" lazy="false" name="firstName" type="string">
<column length="50" name="USR_FIRST_NAME"/>
</property>
<property generated="never" lazy="false" name="lastName" type="string">
<column length="50" name="USR_LAST_NAME"/>
</property>
<property generated="never" lazy="false" name="userName" type="string">
<column length="50" name="USR_USER_NAME" unique="true"/>
</property>
<property generated="never" lazy="false" name="emailAddress" type="string">
<column length="75" name="USR_EMAIL_ADDRESS"/>
</property>
<property generated="never" lazy="false" name="password" type="string">
<column length="50" name="USR_PASSWORD"/>
</property>
<property generated="never" lazy="false" name="created" type="date">
<column name="USR_CREATED"/>
</property>
<set cascade="save-update" lazy="false" inverse="true"
name="userIndexLinks" sort="unsorted">
<key>
<column name="UIL_USR_ID" not-null="true"/>
</key>
<one-to-many class="com.trovare.dal.dto.UserIndexLink"/>
</set>
<set lazy="false" inverse="true" name="userIndexGroupLinks" sort="unsorted">
<key>
<column name="UIGL_USR_ID" not-null="true"/>
</key>
<one-to-many class="com.trovare.dal.dto.UserIndexGroupLink"/>
</set>
<set lazy="false" inverse="true" name="userRoleLinks" sort="unsorted" cascade="all-delete-orphan">
<key>
<column name="URL_USR_ID" not-null="true"/>
</key>
<one-to-many class="com.trovare.dal.dto.UserRoleLink"/>
</set>
<set lazy="false" inverse="true" name="preferences" sort="unsorted">
<key>
<column name="PREF_ID" not-null="true" unique="true"/>
</key>
<one-to-many class="com.trovare.dal.dto.Preference"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
public User save(User user) {
User newUser = null;
try {
HibernateUtil.beginTransaction();
IUserDAO userDAO = getDaoFactory().getUserDAO();
newUser = userDAO.save(user);
HibernateUtil.commitTransaction();
} catch (InfrastructureException e) {
logger.error(e.getLocalizedMessage());
HibernateUtil.rollbackTransaction();
} catch (HibernateException e) {
logger.error(e.getLocalizedMessage());
logger.error(e.getMessage());
HibernateUtil.rollbackTransaction();
} finally {
HibernateUtil.closeSession();
}
return newUser;
}
Full stack trace of any exception that occurs: N/A
Name and version of the database you are using: PostgreSQL 8.3
The generated SQL (show_sql=true):
Hibernate: update PUBLIC.APP_USER set USR_FIRST_NAME=?, USR_LAST_NAME=?, USR_USER_NAME=?, USR_EMAIL_ADDRESS=?, USR_PASSWORD=?, USR_CREATED=? where usr_id=?
Hibernate: select this_.ROL_ID as ROL1_12_0_, this_.ROL_NAME as ROL2_12_0_, this_.ROL_DESCRIPTION as ROL3_12_0_ from PUBLIC.APP_ROLE this_
Hibernate: select this_.ROL_ID as ROL1_12_0_, this_.ROL_NAME as ROL2_12_0_, this_.ROL_DESCRIPTION as ROL3_12_0_ from PUBLIC.APP_ROLE this_
I have a database used to hold user credentials and as part of this I have a user table and a role table and an assoicated join table user_role_link. The user.hbm.xml files maps the user_role_link as a set and has a cascade vlaue of all-delete-orphan, but when I programatically remove a link from the UserRoleLink set in the User object the corresponding row in the user_role_link table is not deleted.