-->
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: Hibernate: Mapping a many-to-many table
PostPosted: Fri Oct 23, 2009 11:45 am 
Newbie

Joined: Wed Oct 07, 2009 2:53 am
Posts: 5
Dear All,

I have been stucked in a problem for nearly a week...I have three tables namely fixture,team,fixture_team....fixture and team have many-to-many relationship and fixture_team is the central table....Their XML mapping is

Code:
        <class name="Fixture" table="fixture">
           <id name="id">
             <generator class="native"/>
           </id>

          <many-to-one
            name="ground"
            column="ground_id"
            class="Ground"
            not-null="true"/>
          <many-to-one
            name="series"
            column="series_id"
            class="Series"
            not-null="true"/>
          <many-to-one
            name="sessionOfPlay"
            column="session_of_play"
            class="AspectVariation"/>

          <set name="teams" inverse="false" cascade="save-update">
            <key column="fixture_id"/>
            <one-to-many class="FixtureTeam"/>
          </set>
       </class>



       <class name="Team" table="team">
         <id name="id">
           <generator class="native"/>
         </id>
         <many-to-one
           name="teamType"
           column="team_type_id"
           class="TeamType"
           not-null="true"/>

         <set name="series" table="series_team">
           <key column="team_id"/>
           <many-to-many column="series_id"
           unique="true"
           class="Series"/>
         </set>

         <set name="fixtures" inverse="true" cascade="save-update">
          <key column="team_id"/>
          <one-to-many class="FixtureTeam"/>
         </set>
      </class>

      <class name="FixtureTeam" table="fixture_team">
       <composite-id >
          <key-many-to-one name="team" class="Team" column="team_id" />
          <key-many-to-one name="fixture" class="Fixture" column="fixture_id" />
        </composite-id>
      </class>



The problem is when I insert "fixture_team" records through setTeams() method of FixtureTeam class as::

Code:
Team team = (Team)s.load(Team.class,new Integer(17));
  Fixture fixture = new Fixture();
  fixture = (Fixture)s.load(Fixture.class, new Integer(1));

  Set set = new HashSet();
  set.add(team);
  fixture.setTeams(set);

  s.merge(fixture);
  s.getTransaction().commit();


I get the following Exception::

Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of uk.co.planetbeyond.Beans.FixtureTeam.team

   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)

   at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:87)

   at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:93)

   at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:109)

   at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:376)

   at org.hibernate.type.ComponentType.replace(ComponentType.java:455)

   at org.hibernate.type.EntityType.replace(EntityType.java:289)

   at org.hibernate.type.CollectionType.replaceElements(CollectionType.java:507)

   at org.hibernate.type.CollectionType.replace(CollectionType.java:574)

   at org.hibernate.type.TypeFactory.replace(TypeFactory.java:505)

   at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:496)

   at org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:267)

   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:240)

   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84)

   at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:705)

   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:689)

   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:693)

   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:324)

   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)

   at $Proxy0.merge(Unknown Source)

   at uk.co.planetbeyond.test.main(test.java:109)

Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class

   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:324)

   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)

   ... 23 more



I am unable to figure out the problem.Thanks in advance.


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.