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.