-->
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.  [ 2 posts ] 
Author Message
 Post subject: Difficulty modelling self-referential many-to-many
PostPosted: Tue Sep 19, 2006 11:27 am 
Newbie

Joined: Wed Aug 16, 2006 4:58 am
Posts: 9
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 class
Code:
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.xml
Code:
<?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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 20, 2006 4:15 am 
Newbie

Joined: Wed Aug 16, 2006 4:58 am
Posts: 9
Once again, I appear to have solved my own problem.

Hibernate can't map this kind of relationship, the inflexion from Hibernate in Action's section on many to many relationships is that the many-to-many must be between two distinct types of object, and that you need to manipulate these in order to modify data. There is no encapsulating data type for this situation, the link table does not easily map to other tables that represent useful data within the domain, so it appears to not be possible to use hibernate here.

Bum.


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

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.