These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: 3 tables, 2 with foreign keys to the third
PostPosted: Fri Aug 25, 2006 10:57 pm 
Newbie

Joined: Fri Aug 25, 2006 10:46 pm
Posts: 1
I have a general question involving 3 tables.

An athlete table
A coack table
A person table

Both athlete and coach should have foreign key references to the person table, that will contain data such as firstName, lastName etc.


My thought was that I would have an AbstractPerson base class that would contain the firstName lastName information, and both person and coach would extend from this base class. But, from what Im reading, it is not good to map an abstract class like AbstractPerson to the abstract table.

My second thought was that I would just create a Person object, that no classes extend from, and the coach and athlete object would delegate its name getters and setters to this Person class. But I cant seem to get the mapping straight.

Here is what I have so far:

<hibernate-mapping>
<class name="btg.athletics.domain.Person" table="person" lazy="false">

<id name="id">
<generator class="increment"/>
</id>

<property name="sport" />
<property name="firstName" />
<property name="lastName" />
</class>

<class name="btg.athletics.domain.Athlete" table="athlete" lazy="false">
<id name="id">
<generator class="increment"/>
</id>

<one-to-one name="person" class="btg.athletics.domain.Person" foreign-key="personId" cascade="all" constrained="true"></one-to-one>
<property name="classStatus" />
<property name="hometown" />
<property name="number" />
<property name="position" />
<property name="height" />
<property name="weight" />
<property name="active" />


</class>

<class name="btg.athletics.domain.Coach" table="coach" lazy="false">
<id name="id" type="integer">
<generator class="increment"/>
</id>
<one-to-one name="person" class="btg.athletics.domain.Person" foreign-key="personId" cascade="all" ></one-to-one>
<property name="description" />
<property name="notes" />

</class>

<class name="btg.athletics.domain.Sport" table="sport">
<id name="id" type="integer">
<generator class="increment"/>
</id>
<property name="name" />
</class>
</hibernate-mapping>

I know this is, in theory, relatively simple, but when I run Im getting the following error.

org.springframework.orm.hibernate3.HibernateSystemException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1

Inside my AbstractPerson constructor, I instantiate a member variable person(Person) so I dont get null pointer exceptions, and the form populates my Pogo with the first and last name.

Thank you so much
Brian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.