-->
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.  [ 6 posts ] 
Author Message
 Post subject: Bogus INSERT into collection link table
PostPosted: Mon Mar 28, 2005 3:00 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Hibernate version: 2.1

Okay, so I've got a lazy Set in an object that has been reattached (using the "Session per request" design model)...

The write-behind does an SQL INSERT into the link table corresponding to this Set, and this INSERT takes a "Duplicate key" error (the link table uses a composite key).

I've instrumented the routine that does the Set.add() to print the return value of the add(). The add() corresponding to this INSERT (correctly) returned [b]false/b]. I think this tells me that the problem is not with implementation of equals()/hashCode().

What might cause Hibernate to do an INSERT for a Set.add() that had returned false?

Thx=a=lot!
—mark—


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:07 pm 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
You have to help hibernate to know if a object is new.

You do this through the "unsaved-value" attribute at a

property
version
timestamp

But the documentation http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-class also says:

Code:
Keep in mind that a version or timestamp property should never be null, no matter what unsaved-value strategy, or an instance will be detected as transient.


Not sure if this helps solving your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:35 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Thanks, but my ID property is a String (using the uuid.hex generator), which is nullable... so, the default unsaved-value should suffice, shouldn't it?

thx,
—ml—


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:45 pm 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
For what I know yes, I just thought it could have something to do with the special handling of the timestamp and version type.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 28, 2005 3:56 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Right. Yeah, I'm not using any versioning or timestamp. Thx for confirming my understanding of the default <unsaved-value> situation...

Any other ideas? :-)

—ml—


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 29, 2005 6:58 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
I see in net.sf.hibernate.collection.Set that add() calls write() (from PersistentCollection) to mark the collection snapshot as dirty; then it calls add() on the underlying hashSet(). So we're dirty whether or not any elements were actually added. OK, so I understand that much... now I just have to figure out why the persister thinks that a new row needs to be inserted in the link table.

Honestly I'm starting to get a little desperate for a breakthrough on this... :-)

Here's the mapping for one end of the association:
Code:

    <set
        name="subscribedPublications"
        table="subscription"
        lazy="true"
        inverse="true"
        cascade="none"
        access="property"
      >
      <key column="subscriber_id"/>
      <many-to-many column="publication_id"
                    class="com.wrinkledog.phydeaux.model.Publication"/>
    </set>

...and the other...
Code:
    <set
        name="subscribers"
        table="subscription"
        access="field"
        lazy="true"
        cascade="none"
      >
      <key column="publication_id"/>
      <many-to-many
          column="subscriber_id"
          class="com.wrinkledog.phydeaux.model.Subscriber"
        />
    </set>

...and the DDL for the association table looks like this:
Code:
create table subscription (
    subscriber_id varchar(32) not null,
    publication_id bigint not null,
    primary key(subscriber_id, publication_id),
    foreign key subscriber_reference (subscriber_id)
                references subscriber(subscriber_id),
    foreign key publication_reference (publication_id)
                references publication(publication_id)
);


Any help much appreciated!
Thx-a-lot,
- mark


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