Hi All!
First off, Versions: Hibernate 2.1.2 and MySQL 3.23.38.
I am having a problem where certain child objects are not being persisted.
Here is my Java code (Objects I am concerned with are created at the bottom):
Code:
session = hibernateGlobal.openSession();
trans = session.beginTransaction();
User adminUser = new User();
adminUser.setName( "admin" );
adminUser.setFirstName( "Luke" );
adminUser.setLastName( "Galea" );
adminUser.setEmail( "admin@gap.ca" );
adminUser.setPassword( "admin" );
List groups = session.find( "from com.gmmsolutions.echobase.datamodel.gap.security.Group as g where g.name='ADMINISTRATOR'" );
Group adminGroup = (Group)groups.get( 0 );
Action userAdminAction = new Action( EchoBaseConstants.ACTION_USERADMIN );
Action userAdminMenuAction = new Action( EchoBaseConstants.ACTION_ADMIN_MENU );
adminGroup.setAllowedActions( new Action[] { userAdminMenuAction, userAdminAction } );
adminUser.setGroups( new Group[] { adminGroup } );
session.saveOrUpdate( adminUser );
//CREATE A NEW LEADER
User leaderUser = new User();
leaderUser.setFirstName( "Vince" );
leaderUser.setLastName( "Puzzella" );
leaderUser.setEmail( "tl@gap.ca" );
leaderUser.setEmployeeID( 409 );
leaderUser.setPassword( "password" );
leaderUser.setEnabled( true );
// set the leader group and action
groups = session.find( "from com.gmmsolutions.echobase.datamodel.gap.security.Group as g where g.name='LEADERS'" );
Group leaderGroup = (Group)groups.get( 0 );
//set the leader group allowed actions
//Action userLeaderAction = new Action( EchoBaseConstants.ACTION_USERADMIN );
//Action userLeaderMenuAction = new Action( EchoBaseConstants.ACTION_ADMIN_MENU );
//leaderGroup.setAllowedActions( new Action[] { userAdminMenuAction, userAdminAction } );
leaderUser.setGroups( new Group[] { leaderGroup } );
session.save( leaderUser, new Long( leaderUser.getEmployeeID() ) );
session.flush();
trans.commit();
trans = session.beginTransaction();
session.refresh( leaderUser );
Iterator iTour = leaderUser.getTours().iterator();
while( iTour.hasNext() )
{
Tour tour = (Tour)iTour.next();
tour.setReport( new Report( tour ) );
session.saveOrUpdate( tour );
}
session.flush();
trans.commit();
The Report object c'tor initializes itself with two Sets of ReportBudgetItem objects and ReportCreditItem objects.
For some reason the ReportCreditItem objects are not being persisted while the ReportBudgetItem objects are persisted.
Here is my XML file:
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 default-cascade="save-update">
<class name="com.gmmsolutions.echobase.datamodel.gap.security.User" table="gapusers">
<cache usage="read-write" />
<id name="uid" type="long" column="userID">
<generator class="native"/>
</id>
<property name="firstName" column="fname" type="string"/>
<property name="lastName" column="lname" type="string"/>
<!--<property name="passwordBlob" column="pwd"/>-->
<property name="password" column="password_new" type="string"/>
<property name="name" column="email" type="string"/>
<property name="enabled" column="enabled" type="boolean"/>
<set name="groups" table="gap_group_user_map" lazy="false">
<key column="gap_user"/>
<many-to-many column="gap_group" class="com.gmmsolutions.echobase.datamodel.gap.security.Group"/>
</set>
<set name="tours" inverse="true" lazy="true">
<key column="LeaderNumber"/>
<one-to-many class="com.gmmsolutions.echobase.datamodel.gap.Tour"/>
</set>
</class>
<class name="com.gmmsolutions.echobase.datamodel.gap.security.Group" table="gapgroups">
<cache usage="read-only"/><!-- CHANGE TO READ-ONLY FOR PRODUCTION-->
<id name="uid" type="long" column="groupID">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<set name="users" table="gap_group_user_map" lazy="true" inverse="true">
<key column="gap_user"/>
<many-to-many column="gap_group" class="com.gmmsolutions.echobase.datamodel.gap.security.Group"/>
</set>
<set name="allowedActions" table="gap_group_allowed_actions" lazy="false">
<key column="user_group"/>
<many-to-many column="action" class="com.gmmsolutions.echobase.datamodel.gap.security.Action"/>
</set>
</class>
<class name="com.gmmsolutions.echobase.datamodel.gap.security.Action" table="echobase_actions">
<cache usage="read-write"/><!-- CHANGE TO READ-ONLY FOR PRODUCTION-->
<id name="uid" type="long" column="uniqueid">
<generator class="native"/>
</id>
<property name="name" column="entityName" type="string"/>
</class>
<class name="com.gmmsolutions.echobase.datamodel.gap.Tour" table="i_tripdates">
<cache usage="read-only"/>
<id name="uid" type="long" column="dateID">
<generator class="native"/>
</id>
<property name="code" column="tcode" type="string"/>
<property name="codeEx" column="TripCode" type="string"/>
<property name="startDate" column="startDate" type="date"/>
<property name="endDate" column="endDate" type="date"/>
<many-to-one name="user" column="LeaderNumber" class="com.gmmsolutions.echobase.datamodel.gap.security.User"/>
<!--<set name="reports" inverse="true" lazy="true">
<key column="tour"/>
<one-to-many class="com.gmmsolutions.echobase.datamodel.gap.Report"/>
</set> -->
<one-to-one name="report" class="com.gmmsolutions.echobase.datamodel.gap.Report"/>
</class>
<class name="com.gmmsolutions.echobase.datamodel.gap.Report" table="gap_reports">
<cache usage="read-write"/>
<id name="uid" type="long" column="tourID">
<generator class="foreign">
<param name="property">tour</param>
</generator>
</id>
<property name="budgetComments" column="budgetComments" type="text"/>
<property name="creditComments" column="creditComments" type="text"/>
<property name="cashFlowComments" column="cashFlowComments" type="text"/>
<property name="creationDate" column="creationDate" type="timestamp"/>
<property name="lastModifiedDate" column="lastModifiedDate" type="timestamp"/>
<property name="status" column="status" type="int"/>
<property name="singles" column="singles" type="int"/>
<property name="doubles" column="doubles" type="int"/>
<!--<many-to-one name="tour" column="tour" class="com.gmmsolutions.echobase.datamodel.gap.Tour"/> -->
<one-to-one name="tour" class="com.gmmsolutions.echobase.datamodel.gap.Tour" constrained="true"/>
<set name="budgetItems" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="report"/>
<one-to-many class="com.gmmsolutions.echobase.datamodel.gap.ReportBudgetItem"/>
</set>
<set name="creditItems" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="report"/>
<one-to-many class="com.gmmsolutions.echobase.datamodel.gap.ReportCreditItem"/>
</set>
<set name="wireDeposits" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="report"/>
<one-to-many class="com.gmmsolutions.echobase.datamodel.gap.WireDeposit"/>
</set>
</class>
<class name="com.gmmsolutions.echobase.datamodel.gap.ReportNamedItem" table="gap_reportItems" >
<cache usage="read-write"/>
<id name="uid" type="long" column="uniqueid">
<generator class="native"/>
</id>
<discriminator column="itemType" type="string"/>
<property name="name" column="name" type="string"/>
<property name="amount" column="amount" type="float"/>
<property name="comments" column="comments" type="text"/>
<many-to-one name="report" column="report" class="com.gmmsolutions.echobase.datamodel.gap.Report"/>
<subclass name="com.gmmsolutions.echobase.datamodel.gap.ReportBudgetItem" discriminator-value="BUDGET">
<!--<key column="reportID"/>-->
<set name="dailies" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="reportBudgetItem"/>
<one-to-many class="com.gmmsolutions.echobase.datamodel.gap.ReportDailyItem"/>
</set>
</subclass>
<subclass name="com.gmmsolutions.echobase.datamodel.gap.ReportCreditItem" discriminator-value="CREDIT">
<!--<key column="reportID"/> -->
</subclass>
</class>
<class name="com.gmmsolutions.echobase.datamodel.gap.ReportDailyItem" table="gap_dailyItem">
<cache usage="read-write"/>
<id name="uid" type="long" column="uniqueid">
<generator class="native"/>
</id>
<property name="amount" column="amount" type="float"/>
<property name="day" column="day" type="int"/>
<!--<property name="comments" column="comments" type="text"/>-->
<many-to-one name="reportBudgetItem" column="reportBudgetItem" class="com.gmmsolutions.echobase.datamodel.gap.ReportBudgetItem"/>
</class>
<class name="com.gmmsolutions.echobase.datamodel.gap.WireDeposit" table="gap_wireDeposits">
<cache usage="read-write"/>
<id name="uid" type="long" column="uniqueid">
<generator class="native"/>
</id>
<property name="accountNumber" column="accountNumber" type="int"/>
<property name="amount" column="amount" type="float"/>
<property name="bankName" column="bankName" type="string"/>
<property name="date" column="date" type="timestamp"/>
<many-to-one name="report" column="report" class="com.gmmsolutions.echobase.datamodel.gap.Report"/>
</class>
</hibernate-mapping>
TIA!