Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1104409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:28:48+00:00 2026-05-17T01:28:48+00:00

I have a bag whose structure looks like this: <bag name=foo fetch=select table=table_of_foos> <key

  • 0

I have a bag whose structure looks like this:

<bag name="foo" fetch="select" table="table_of_foos">
    <key column="foo_ids"/>
    <many-to-many class="Bar" column="bar_ids"/>
</bag>

My “table_of_foos” table has two columns: “foo_ids” and “bar_ids”, neither of which is unique. I want to add another column to this table that holds some information about the relationship of foos to bars, so that my table would hold three columns. Then, I want to be able to access this information in my webapp.

Unfortunately, it doesn’t seem as if I can add a property or an element to the bag. What I want to do is something like this:

<bag name="foo" fetch="select" table="table_of_foos">
    <key column="foo_ids"/>
    <many-to-many class="Bar" column="bar_ids"/>
    <element column="still_valid" type="integer"/>
</bag>

What is the best way to accomplish this?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:28:49+00:00Added an answer on May 17, 2026 at 1:28 am

    If your joined Table needs an additional column other than its (composite) primary-key, you must implement an additional joined class.

    public class Foo {
    
        Collection<FooBar> bar = new ArrayList<FooBar>();
    
    }
    
    public class Bar {
    
        Collection<FooBar> foo = new ArrayList<FooBar>();
    
    }
    

    The joined class (which needs a composite primary key – implemented as a static inner class) is described as follows

    public class FooBar {
    
        private FooBarId fooBarId;
    
        private String additionalProperty;
    
        public static class FooBarId implements Serializable {
    
            private Integer fooId;
            private Integer barId;
    
            private Foo foo;
            private Bar bar;
    
            // getter's and setter's
    
            public FooBarId() {}
            public FooBarId(Integer fooId, Integer barId) {
                this.fooId = fooId;
                this.barId = barId;
            }
    
            public boolean equals(Object o) {
                if(!(o instanceof FooBarId))
                    return false;
    
                FooBarId other = (FooBarId) o;
                return new EqualsBuilder()
                           .append(getFooId(), other.getFooId())
                           .append(getBarId(), other.getBarId())
                           .isEquals();
            }
    
            public int hashCode() {
                return new HashCodeBuilder()
                           .append(getFooId())
                           .append(getBarId())
                           .hashCode();
            }
    
        }
    
    }
    

    re-write your mapping as

    /* Foo.class */ 
    
    <bag name="bar" table="table_of_foos">
        <key column="BAR_ID" insert="false" update="false"/>
        <one-to-many class="FooBar" table="table_of_foos"/>
    </bag>
    
    /* Bar.class */ 
    
    <bag name="foo" table="table_of_foos">
        <key column="FOO_ID" insert="false" update="false"/>
        <one-to-many class="FooBar" table="table_of_foos"/>
    </bag>
    

    And FooBar mapping

    <class name="FooBar">
        <composite-id name="fooBarId" class="FooBar$FooBarId">
            <key-property name="fooId" column="FOO_ID"/>
            <key-property name="barId" column="BAR_ID"/>
        </composite-id>
        <property name="additionalProperty" type="string"/>
        <many-to-one name="foo" column="FOO_ID" class="Foo" insert="false" update="false"/>
        <many-to-one name="bar" column="BAR_ID" class="Bar" insert="false" update="false"/>
    </class>
    

    If you want, you can also map a composite element instead of a joined class (A component element does not need a (composite) primary key and has its has its lifecycle bound to that of its owning Entity instance. Keep this in mind)

    Create you composite element (now without identifier)

    public class FooBar {
    
        private String additionalProperty;
    
        private Foo foo;
        private Bar bar;
    
    }
    

    And define the following mapping

    /* Foo.class */ 
    
    <bag name="bar" table="table_of_foos">
        <key column="BAR_ID"/>
        <composite-element class="FooBar">
            <property name="additionalProperty" type="string"/>
            <many-to-one name="foo" column="FOO_ID" class="Foo" insert="false" update="false"/>
            <many-to-one name="bar" column="BAR_ID" class="Bar"/>
        </composite-element>
    </bag>
    
    /* Bar.class */ 
    
    <bag name="foo" table="table_of_foos">
        <key column="FOO_ID"/>
        <composite-element class="FooBar">
            <property name="additionalProperty" type="string"/>
            <many-to-one name="foo" column="FOO_ID" class="Foo" insert="false" update="false"/>
            <many-to-one name="bar" column="BAR_ID" class="Bar"/>
        </composite-element>
    </bag>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have: <bag name=Categories table=CMS_Articles_Categories lazy=true> <key column=article_id/> <many-to-many class=Framework.CMS.Domain.Category, Framework.CMS column=category_id/> </bag> This
I have a folder structure like follows. -FOO -BAG Rose.TXT -BAR JaCk.txt I need
I have a string that looks like this: (Boxing Bag@bag.jpg@To punch and kick)(Wallet@wallet.jpg@To keep
i have a collection in the mapping: <bag name=Values cascade=all-delete-orphan lazy=false inverse=true> <key column=[TemplateId]/>
I have a class like this: template <class T> class bag { private: typedef
I have the following scenario in nHibernate: <class name=TestApp.Components.User,TestApp.Components table=Users> <id name=Id column=UserId type=Int32
We have an Email object. The email.hbm has <bag name=emailRecipients lazy=false inverse=false cascade=save-update fetch=select>
I have a schema that looks like this User Id INT Username VARCHAR(100) Password
In Symfony 2 i have a yml file like this: my_application: application: name: Hello
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.