-->
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.  [ 8 posts ] 
Author Message
 Post subject: Subtle problem with indexed lists
PostPosted: Fri Nov 18, 2005 10:19 am 
Newbie

Joined: Fri Nov 18, 2005 9:54 am
Posts: 4
Hello all,

I have a very subtle problem with one-to-many bidirectional associations based on indexed lists, using Hibernate 3.0.5

I've mapped my association following the instructions given in this document: http://www.hibernate.org/193.html

So, this is my parent mapping:

Code:
<list cascade="all-delete-orphan" inverse="false" lazy="true"
  name="requiredDocuments">
           <cache usage="read-write"/>
           <key column="enrollmentRequest"/>
           <index column="displayOrder"/>
           <one-to-many class="com.foo.EnrollmentRequestDocument"/>
</list>


And this is my child mapping:

Code:
<many-to-one cascade="none" insert="false" lazy="proxy"
  name="enrollmentRequest" not-null="false" update="false"/>


Finally, this is my "add" method in the parent class:

Code:
public void addDocument(EnrollmentRequestDocument document) {
        document.setEnrollmentRequest(this);
        this.requiredDocuments.add(document);
}


Notice that in the child mapping I had to write not-null="FALSE" because if I set it to TRUE I get a not-null constraint violation when inserting.

However, this doesn't work. The foreign key in the child is not set, nor is set the index column during saving.

Am I missing something relevant?

Thanks in advance,

Sergio B.

_________________
Sergio Bossa
(http://sbtourist.blogspot.com)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 11:39 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
if your association is bidirectionnal, why inverse=false?

Next, the reference guide says:
A bidirectional association allows navigation from both "ends" of the association. Two kinds of bidirectional association are supported:

one-to-many

set or bag valued at one end, single-valued at the other

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 11:54 am 
Newbie

Joined: Fri Nov 18, 2005 9:54 am
Posts: 4
anthony wrote:
if your association is bidirectionnal, why inverse=false?


Because it is implemented as an indexed collection, a list, which, according to http://www.hibernate.org/193.html, cannot be managed in inverse fashion.

Recall:

Quote:
Hibernate 3 allows you to use indexed collections in a bidirectional association without workaround, just use this mapping:

Parent
<list inverse="false"/>
</list>

Child
<many-to-one insert="false" update="false"/>

To summarize, you need to let the collection be the owner side.


Is this maybe wrong?

Thank you for your interest,

Regards,

Sergio B.

_________________
Sergio Bossa
(http://sbtourist.blogspot.com)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 12:01 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
oh sorry i forgot this was possible with H3.

This should work... strange



Code:
public void addDocument(EnrollmentRequestDocument document) {
    what if document.getEnrollmentRequest != null ?
you must remove the document from its old EnrollmentRequest
    document.setEnrollmentRequest(this);
    this.requiredDocuments.add(document);
}

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 12:15 pm 
Newbie

Joined: Fri Nov 18, 2005 9:54 am
Posts: 4
anthony wrote:
This should work... strange


Yes, very strange ... no idea?

anthony wrote:
Code:
public void addDocument(EnrollmentRequestDocument document) {
    what if document.getEnrollmentRequest != null ?
you must remove the document from its old EnrollmentRequest
    document.setEnrollmentRequest(this);
    this.requiredDocuments.add(document);


This doesn't matter because never happens due to business requirements.

Any help?

Regards,

Sergio B.

_________________
Sergio Bossa
(http://sbtourist.blogspot.com)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
please show id mapping file tags and Hibernate API calls

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 12:37 pm 
Newbie

Joined: Fri Nov 18, 2005 9:54 am
Posts: 4
anthony wrote:
please show id mapping file tags and Hibernate API calls


Id mappings are simple:

Code:
<id column="id" name="id" unsaved-value="null">
   <generator class="native"/>
</id>


And I cannot show you Hibernate API calls because I'm using the HibernateDAOSupport class provided by the Spring framework.

Regards,

Sergio B.

_________________
Sergio Bossa
(http://sbtourist.blogspot.com)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 12:08 am 
Beginner
Beginner

Joined: Sat Oct 29, 2005 2:05 am
Posts: 21
Location: Kansas City, KS
Try using <list-index> instead of <index>.

I'd like to see more of the mapping definition, the generated SQL for the table definitions, and the constraint violation message. Turn on the debugger and post the results.

You have to be careful with index columns and not-null values in order to get the correct constraint definitions. In particular, Hibernate does not support list-to-list, but that doesn't appear to be what you're attempting.


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