-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-many issue, list inverse="true", bag inver
PostPosted: Thu Dec 30, 2004 10:01 pm 
Newbie

Joined: Tue Dec 09, 2003 2:27 am
Posts: 7
Location: Sydney -
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:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 31, 2004 6:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://www.hibernate.org/hib_docs/refer ... ollections

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 01, 2005 9:30 am 
Newbie

Joined: Tue Dec 09, 2003 2:27 am
Posts: 7
Location: Sydney -
I had already read the hibernate reference and there is very little of the actual use of lists. I was trying to use a list of one side and a bag on there other. I went back and tried things with a list on both sides and created another issue.

With a list of both sides of the mapping. This time the index value for all the albums was 0, this make sense if it is the index of the collection from the album side. Thinking about it if there is a list of both sides of a many-to-many mapping that the index for each should be different. I fI make them different the I get the same issue as before i.e. '"pos_album" violates not-null constraint'

I'm probably doing something wrong, but can't see what it is. If I'm not then there is a issue with the way hibernate handles many-to-many relationships inside a list.

Gary


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.