I'm sorry - I'm not thinking clearly.
I did one experiment that makes me feel better. I removed the one-to-many and inverse relationships from both classes, altered the tables to eliminate the foreign key constraints, and re-ran the code to see if I could persist Player and Team objects. Both were successful (thank God).
As you're suggesting, it's my mistake with the one-to-many and inverse relationships that's causing the problem.
I've put back those XDoclet tags and regenerated the hbm.xml mappings:
example.Players.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="example.Player"
table="players"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="player_id"
type="long"
unsaved-value="null"
>
<generator class="sequence">
</generator>
</id>
<property
name="annualSalary"
type="float"
update="true"
insert="true"
column="annual_salary"
/>
<property
name="draftDate"
type="date"
update="true"
insert="true"
column="draft_date"
/>
<property
name="firstName"
type="string"
update="true"
insert="true"
column="first_name"
length="15"
/>
<property
name="jerseyNumber"
type="integer"
update="true"
insert="true"
column="jersey_number"
length="1"
/>
<property
name="lastName"
type="string"
update="true"
insert="true"
column="last_name"
length="15"
not-null="true"
/>
<many-to-one
name="team"
class="example.Team"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
column="team_id"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Player.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
example.Teams.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="example.Team"
table="teams"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="team_id"
type="long"
unsaved-value="null"
>
<generator class="sequence">
</generator>
</id>
<property
name="city"
type="string"
update="true"
insert="true"
column="city"
length="15"
not-null="true"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
length="20"
not-null="true"
/>
<set
name="players"
table="players"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>
<key
column="player_id"
/>
<one-to-many
class="example.Player"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Team.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
I reviewed the documentation more carefully this time, because I believe it worked. If you spot anything else that I ought to correct, I'd appreciate hearing about it.
One question: the players table has a foreign key to the teams table, but the inverse is NOT true. Correct? (Makes sense for one-to-many, I guess.)
But thanks again for your help and patience. Sincerely, MOD