-->
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.  [ 1 post ] 
Author Message
 Post subject: bidirectional one-to-many association on a join table
PostPosted: Thu Aug 09, 2007 3:05 pm 
Newbie

Joined: Thu Aug 09, 2007 12:13 pm
Posts: 1
I have 3 tables as follows:

    documents
    document_tables
    tables

A document can have many tables. A table can belong to one and only one document. A document has a collection of tables.

document.hbm.xml
Code:
<bag name="tables" table="document_tables" lazy="false" cascade="save-update">
    <key column="document_id" />
    <many-to-many column="table_id" unique="true" class="org.aafp.jms.model.AbstractTable" />
</bag>


table.hbm.xml
Code:
<join table="document_tables" inverse="true" optional="true">
    <key column="table_id"/>
    <many-to-one name="document" column="document_id" not-null="true"/>
</join>


This works great. But I cannot do a mapping that has a subset of the entire collection of tables based on a field that is in the tables table. Is there some way to expose the field I need for the subset criteria. If I didn't have to map it like this with the many-to-many table in the middle I could use the where clause of the bag. I can't do that because I have a similar setup for another entity.

    tips
    tips_tables
    tables

I'm relegated to using something like what follows:

AbstractDocument.java
Code:
public List getSupplementalTables() {
        List supplementalTables = new ArrayList();

        for (Iterator it = getTables().iterator(); it.hasNext();) {
            AbstractTable table = (AbstractTable) it.next();

            if (table.isSupplemental()) {
                supplementalTables.add(table);
            }
        }

        return supplementalTables;
    }


Now, I loop through and spring:bind a supplemental table object property named order to a mvc view.

Code:
<spring:bind path="document.supplementalTables[${count.index}].order">
    <input type="text" size="2" maxlength="2" name="${status.expression}" value="${status.value}" /><br/>
</spring:bind>


I'm getting strange results from editing this view.

Any thoughts or help is greatly appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.