Hi I am trying to manipulate this many-to-many self-referential association. The paradigm is that a user may have many users as members of thier roster. I am encountering problems adding records to the database.
Table SQL:
Quote:
CREATE TABLE roster_members
(
"owner" int8 NOT NULL,
member int8 NOT NULL,
CONSTRAINT roster_members_pkey PRIMARY KEY ("owner", member),
CONSTRAINT roster_member_member FOREIGN KEY ("owner")
REFERENCES user_players (player_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT roster_member_owner FOREIGN KEY ("owner")
REFERENCES user_players (player_id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
WITHOUT OIDS;
ALTER TABLE roster_members OWNER TO root;
Mapped classCode:
public class RosterMember implements IPrimitiveEncodable, Serializable
{
private static final long serialVersionUID = 661036122775092120L;
protected UserID owner_id;
protected UserID user_id;
/*============HIBERNATE ACCESS FUNCTIONS============*/
private RosterMember(){}
private Long getOwnerId(){ return this.owner_id.key(); }
private void setOwnerId(Long _id){this.owner_id = new UserID(_id); }
private Long getMemberId(){ return this.user_id.key(); }
private void setMemberId(Long _id){this.user_id = new UserID(_id); }
}
Mapping documents: RosterMember.hbm.xmlCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="uk.co.dubit.nexus.roster.RosterMember" table="roster_members">
<composite-id class="uk.co.dubit.nexus.roster.RosterMember">
<key-property
name="ownerId"
column="owner"
type="long" />
<key-property
name="memberId"
column="member"
type="long" />
</composite-id>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
private void addMember(RosterMember _member)
{
Session _session = this.sessoFactory.openSession();
_session.save(_member);
}
Full stack trace of any exception that occurs:Quote:
org.hibernate.HibernateException: The class has no identifier property: uk.co.dubit.nexus.roster.RosterMember
at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:167)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3257)
at org.hibernate.id.Assigned.generate(Assigned.java:28)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at uk.co.dubit.nexus.db.HibernateRosterDao.addMember(HibernateRosterDao.java:133)
at uk.co.dubit.nexus.roster.RosterApplication.addMember(RosterApplication.java:99)
at uk.co.dubit.tests.nexus.RosterApplicationTest.testIsMember(RosterApplicationTest.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Hibernate version: 3.1
Name and version of the database you are using: Postgres 8.1
The generated SQL (show_sql=true): none
Any help is greatly appreciated.