-->
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.  [ 7 posts ] 
Author Message
 Post subject: Cascade with index-many-to-many
PostPosted: Wed Feb 25, 2004 7:58 am 
Newbie

Joined: Wed Oct 01, 2003 10:52 am
Posts: 6
Location: Oslo, Norway
I'm having some trouble getting cascading saves working with a map. I have a class Digest which contains a map of Query objects and number of occurance pairs. Since I am using an object a a key in the map, I used an index-many-to-many association for the map's index.

The problem arises whrn I try to save an instance of the Digest class. Nothing related to the map is saved... no Query objects and no relationship information in the Map table. Since I have cascade set to 'all', I expected a save of the Digest object to save all the objects and data int he map.

Is this a correct expectation? Everythign seems to work as I would expect if the map uses a String or Int as a key (and then not using the index-many-to-many association). Does the index-many-to-many change cascade sematics?

-mike



This is the mapping for my 'Digest' class, which contains a map of Query objects and number of times that query occured.

Code:
<?xml version="1.0"?>
<hibernate-mapping>
    <class
        name="no.fast.vespa.model.reporting.test.Digest"
        table="Digest"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <map
            name="querys"
            table="Querys"
            lazy="false"
            sort="unsorted"
            inverse="false"
            cascade="all"
        >

              <key
                  column="digest_id"
              />

              <index-many-to-many
                  class="no.fast.vespa.model.reporting.test.Query"
                  column="query_id"
              />

              <element
                  column="occurances"
                  type="integer"
                  not-null="true"
                  unique="false"
              />

        </map>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="name"
            not-null="true"
            unique="false"
        />

       

    </class>

</hibernate-mapping>


And this is the actual Query class

Code:


<hibernate-mapping>
    <class
        name="no.fast.vespa.model.reporting.test.Query"
        table="Query"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="queryTerm"
            type="java.lang.String"
            update="true"
            insert="true"
            column="queryTerm"
            not-null="true"
            unique="true"
        />

     

    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 9:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Did you set equals/hashCode of Query ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 11:28 am 
Newbie

Joined: Wed Oct 01, 2003 10:52 am
Posts: 6
Location: Oslo, Norway
Quote:
Did you set equals/hashCode of Query ?


Yes, I implemented hashcode() and equals(), using the 'semi-unique key with business meaning' strategy discussed at http://hibernate.org/109.html... here is the actual code

Code:
    public boolean equals(Object obj) {
        return (obj instanceof no.fast.vespa.model.reporting.test.Query
                && this.queryTerm == ((Query) obj).getQueryTerm());
    }

    public int hashCode() {
        return 17 * this.queryTerm.hashCode();
    }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 12:26 pm 
Newbie

Joined: Wed Oct 01, 2003 10:52 am
Posts: 6
Location: Oslo, Norway
I have played with this some more, and found another twist I don't understand. If I run the following code with the flush() commented out, it saves the digest object, but not the contained Query object. But if I run it with the flush() uncommented, I get a transient object exception. Is this expected behavior, or I am jsut completely confused about what I am trying to do?

Code:
Digest d = new Digest();
d.setName("Test Digest");

Query q = new Query("test query 1");
d.addQuery(q);
Session s = this.sf.openSession();
s.save(d);
//s.flush();
s.close();


Thanks again, -mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 10:27 am 
Newbie

Joined: Wed Oct 01, 2003 10:52 am
Posts: 6
Location: Oslo, Norway
Bump... still confused and needing some help :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 1:51 pm 
Newbie

Joined: Thu Dec 11, 2003 6:21 am
Posts: 8
As far as I know cascades are not supported for collection indexes.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 6:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
snek wrote:
As far as I know cascades are not supported for collection indexes.

You are mistaken. Bidirectional mapping is not supported.

_________________
Emmanuel


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