-->
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: Can you use Lists inside a subclass
PostPosted: Mon Jan 26, 2004 6:33 pm 
Newbie

Joined: Mon Nov 17, 2003 1:51 am
Posts: 16
I have a list inside a subclass mapped as follow:
Code:
<class
        name="com.realtor.domain.user.Person"
        table="person"
        dynamic-update="true"
        dynamic-insert="false"
        discriminator-value="Person"
    >
....
<subclass
            name="com.realtor.domain.realestate.Agent"
            dynamic-update="true"
            dynamic-insert="true"
            discriminator-value="agent"
        >

        <list
            name="listings"
            lazy="false"
            inverse="false"
            cascade="save-update"
        >

              <key
                  column="agent_id"
              />

              <index
                  column="agent_listing_idx"
              />

              <many-to-many
                  class="com.realtor.domain.realestate.Listing"
                  column="listing_id"
                  outer-join="auto"
              />

        </list>
...
</subclass>

Inside Listing's mapping
Code:
        <many-to-one
            name="agent"
            class="com.realtor.domain.realestate.Agent"
            cascade="save-update"
            outer-join="auto"
            update="true"
            insert="true"
            column="agent_id"
        />

When I add listings to the Agent's listings List The listings table in the database is not updated but the foreign keys are set correctly in the listing table.

The listings schema is
listing_id agent_id agent_listing_idx
This table (listings) is not updated
The listing schema has an agent_id as a foreign key that get updated when I insert into the collection.
FOREIGN KEY (agent_id) REFERENCES person(id)


I often use this mapping with no problem the only difference this time is that it's inside a subclass.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It surely works. Most likely your insert code is wrong... please show.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 6:59 pm 
Newbie

Joined: Mon Nov 17, 2003 1:51 am
Posts: 16
Inside Agent.java

Code:
private List listings = new ArrayList();
...

public void addListing(Listing listing){
       listing.setAgent(this);
       this.listings.add(listing);
   }
...


public void setListings(List theListings) {
        this.listings.clear();
        Iterator iterator = theListings.iterator();
        while(iterator.hasNext()){
            Listing listing = (Listing) iterator.next();
            this.addListing(listing);
        }       
    }



You were right my insert code was wrong. setListings was clearing the list.
What is the recommended way to set a List?
thanks


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.