-->
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: Many-to-many problems.
PostPosted: Thu May 13, 2004 8:56 am 
Newbie

Joined: Wed Sep 03, 2003 8:55 am
Posts: 7
Hi,

I'm having problems with very basic many-to-many association - the actual association is not getting into the database although both participating objects are saved..

Here is the info:

Hibernate 2.1.3
MySQL 4.0.15

Mappings:
======

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="fiifoo"
                   default-cascade="save-update">
   <class name="Foo">
      <id name="id" unsaved-value="0">
         <generator class="native"/>
      </id>
     
      <set name="fiis" table="fiifoo" inverse="true">
         <key column="foo"/>
         <many-to-many column="fii" class="Fii">
            
         </many-to-many>
      </set>
   </class>
</hibernate-mapping>


Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="fiifoo"
                   default-cascade="save-update">
   <class name="Fii">
      <id name="id" unsaved-value="0">
         <generator class="native"/>
      </id>
     
      <set name="foos" table="fiifoo">
         <key column="fii"/>
         <many-to-many column="foo" class="Foo">
            
         </many-to-many>
      </set>
   </class>
</hibernate-mapping>


Code:
=====

Code:
   public static void main( String[] args )
   throws Throwable {
      SessionFactory factory = new Configuration().buildSessionFactory() ;
     
      Session session = factory.openSession() ;
     
      Fii fii = new Fii() ;
      Foo foo = new Foo() ;
     
      Set fiis = new HashSet() ;
      Set foos = new HashSet() ;
     
      fiis.add( fii ) ;
      foos.add( foo ) ;
     
      fii.setFoos( foos ) ;
      foo.setFiis( fiis ) ;
     
      session.save( fii ) ;
      session.save( foo ) ;
     
      session.close() ;
   }


Output (snippets):
=====

Code:
15:48:47,835 DEBUG SchemaExport:132 - drop table if exists Fii
15:48:47,845 DEBUG SchemaExport:132 - drop table if exists fiifoo
15:48:47,845 DEBUG SchemaExport:132 - drop table if exists Foo
15:48:47,855 DEBUG SchemaExport:149 - create table Fii (
   id INTEGER NOT NULL AUTO_INCREMENT,
   primary key (id)
)
15:48:47,865 DEBUG SchemaExport:149 - create table fiifoo (
   foo INTEGER not null,
   fii INTEGER not null,
   primary key (fii, foo)
)
15:48:47,875 DEBUG SchemaExport:149 - create table Foo (
   id INTEGER NOT NULL AUTO_INCREMENT,
   primary key (id)
)
15:48:47,895 DEBUG SchemaExport:149 - alter table fiifoo add index (foo), add constraint FKB4073B0018CC6 foreign key (foo) references Foo (id)
15:48:47,925 DEBUG SchemaExport:149 - alter table fiifoo add index (fii), add constraint FKB4073B0018C06 foreign key (fii) references Fii (id)
15:48:47,965  INFO SchemaExport:160 - schema export complete


Code:
Hibernate: insert into Fii values ( )
Hibernate: insert into Foo values ( )




The last output block is everything I get by setting showSql to true.. So it's not even attempting to insert anything to fiifoo.. :(

Any help will be greatly appreciated..

.shoka.

_________________
.shoka.


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.