I'm trying to us a many-to-many relationship with a list on the inverse true side and a bag on the other.
It appears to me that the db schema generated might be incorrect (or my mapping files are wrong). When I try to do a saveOrUpdate I get a JDBC error that the index violates not-null constraint.
Details follow.
Thanks
Gary
Hibernate version:2.1.6
Mapping documents: <hibernate-mapping> <class name="Collection" table="ff_collection"> <id name="id" column="id" type="java.lang.String" unsaved-value="null"> <generator class="uuid.hex"/> </id>
<list name="albums" table="ref_collection_album" lazy="false" inverse="true" cascade="save-update"> <key column="collectionid"/> <index column="posid" type="java.lang.Integer"/> <many-to-many class="net.sf.fotoflow.gensrc.modelv1.Album" column="albumid"/> </list> </class> </hibernate-mapping>
<hibernate-mapping> <class name="Album" table="ff_album"> <id name="id" column="id" type="java.lang.String" unsaved-value="null"> <generator class="uuid.hex"/> </id>
<bag name="collections" table="ref_collection_album" lazy="false" cascade="save-update"> <key column="albumid"/> <many-to-many class="net.sf.fotoflow.gensrc.modelv1.Collection" column="collectionid"/> </bag> </class> </hibernate-mapping>
Generate Schema
template1=# \d ref_collection_album
Table "public.ref_collection_album"
Column | Type | Modifiers
--------------+------------------------+-----------
collectionid | character varying(255) | not null
albumid | character varying(255) | not null
posid | integer | not null
Indexes:
"ref_collection_album_pkey" primary key, btree (collectionid, posid)
Foreign-key constraints:
"fk31ed23ba61848c39" FOREIGN KEY (collectionid) REFERENCES ff_collection(id)
"fk31ed23bac923abca" FOREIGN KEY (albumid) REFERENCES ff_album(id)
Code between sessionFactory.openSession() and session.close():
Collection col = new Collection();
Album newAlbum = new Album();
col.addAlbum( newAlbum );
session.saveOrUpdate( newAlbum );
Full stack trace of any exception that occurs:
11:19:23,795 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: null
11:19:23,795 ERROR JDBCExceptionReporter:46 - Batch entry 0 insert into ref_collection_album (albumid, collectionid) values ( was aborted. Call getNextException() to see the cause.
11:19:23,805 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: 23502
11:19:23,805 ERROR JDBCExceptionReporter:46 - ERROR: null value in column "posid" violates not-null constraint
11:19:23,805 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: null
11:19:23,815 ERROR JDBCExceptionReporter:46 - Batch entry 0 insert into ref_collection_album (albumid, collectionid) values ( was aborted. Call getNextException() to see the cause.
11:19:23,815 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: 23502
11:19:23,815 ERROR JDBCExceptionReporter:46 - ERROR: null value in column "posid" violates not-null constraint
11:19:23,825 ERROR JDBCExceptionReporter:38 - Could not execute JDBC batch update
Batch entry 0 insert into ref_collection_album (albumid, collectionid) values ( was aborted. Call getNextException() to see the cause.
Name and version of the database you are using:
Postgres 7.1.4
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|