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

  • SEARCH
  • Home
  • 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 6224485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:40:53+00:00 2026-05-24T08:40:53+00:00

I have a table called SecurityContacts and another table called Contacts. The association between

  • 0

I have a table called SecurityContacts and another table called Contacts. The association between them is ManyToOne. SecurityContacts has columns for both an AgentContact and an AuditContact, which are two different types of contacts. It also has a column for the security_id associated with both of those contacts. These two contacts join with the primary key of Contacts, which is contact_id.

Here is an example of the problem: Suppose an entry in SecurityContact exists as such: AgentContact = 5, AuditContact= NULL, security_id=1000. You try to set the AuditContact of that existing entry as 6. Hibernate creates a second entry as such: AgentContact=Null, AuditContact=6, security_id=1000. What should happen is that the existing entry should be modified to be: AgentContact = 5, AuditContact = 6, security_id=1000.

The interesting thing about this is that if both AgentContact and AuditContact are already set to any existing value in Contact, instead of NULL, the update works properly. This leads me to believe it might be an outer/inner join problem. Here is the code for my SecurityContacts table:

/**
 * The persistent class for the SecurityContact database table.
 * 
 */
@Entity
@FXClass(kind=FXClassKind.REMOTE)
public class SecurityContact implements Serializable {
    private static final long serialVersionUID = 1L;
    @Transient private String uid;
    @FXIgnore
    public String getUid() {
        if (uid == null) {
            uid = "" + securityContactId;
        }
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="securityContact_id")
    private Long securityContactId;

    @Column(name="security_id")
    private String securityId;

    @Column(name="create_date")
    private String createDate;

    @Column(name="create_user")
    private String createUser;

    @Column(name="modify_date")
    private String modifyDate;

    @Column(name="modify_user")
    private String modifyUser;

    //bi-directional many-to-one association to AgentContact

    @ManyToOne
    @JoinColumn(name="agent_id", referencedColumnName="contact_id")
    private AgentContact agentContact;

    //bi-directional many-to-one association to AuditContact
    @ManyToOne
    @JoinColumn(name="audit_id", referencedColumnName="contact_id")
    private AgentContact auditContact;

    public SecurityContact() {
    }
    @FXKeyColumn
    public Long getSecurityContactId() {
        return this.securityContactId;
    }

    public void setSecurityContactId(Long securityContactId) {
        this.securityContactId = securityContactId;
    }

    public String getSecurityId() {
        return this.securityId;
    }

    public void setSecurityId(String securityId) {
        this.securityId = securityId;
    }

    public String getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getCreateUser() {
        return this.createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public String getModifyDate() {
        return this.modifyDate;
    }

    public void setModifyDate(String modifyDate) {
        this.modifyDate = modifyDate;
    }

    public String getModifyUser() {
        return this.modifyUser;
    }

    public void setModifyUser(String modifyUser) {
        this.modifyUser = modifyUser;
    }
    @FXManyToOne(parent="parent", property="contactId")
    public AgentContact getAgentContact() {
        return this.agentContact;
    }

    public void setAgentContact(AgentContact agentContact) {
        this.agentContact = agentContact;
    }
    @FXManyToOne(parent="parent", property="contactId")
    public AgentContact getAuditContact() {
        return this.auditContact;
    }

    public void setAuditContact(AgentContact auditContact) {
        this.auditContact = auditContact;
    }

} 

Here is the code for my Contacts table:

/**
 * The persistent class for the AgentContact database table.
 * 
 */
@Entity
@FXClass(kind=FXClassKind.REMOTE)
public class AgentContact implements Serializable {
    private static final long serialVersionUID = 1L;
    @Transient private String uid;
    @FXIgnore
    public String getUid() {
        if (uid == null) {
            uid = "" + contactId;
        }
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="contact_id")
    private Long contactId;

    @ManyToOne
    @JoinColumn(name="bank_id")
    private Bank bank;

    @Column(name="create_date")
    private String createDate;

    @Column(name="create_user")
    private String createUser;

    private String email;

    private String fax;

    @Column(name="modify_date")
    private String modifyDate;

    @Column(name="modify_user")
    private String modifyUser;

    private String name;

    private String phone;

    //bi-directional many-to-one association to SecurityContact
    @OneToMany(mappedBy="agentContact")
    private Set<SecurityContact> securityContacts;


    public AgentContact() {
    }
    @FXKeyColumn
    public Long getContactId() {
        return this.contactId;
    }

    public void setContactId(Long contactId) {
        this.contactId = contactId;
    }
    @FXManyToOne(parent="parent", property="bankId")
    public Bank getBank() {
        return this.bank;
    }

    public void setBank(Bank bank) {
        this.bank = bank;
    }

    public String getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getCreateUser() {
        return this.createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFax() {
        return this.fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getModifyDate() {
        return this.modifyDate;
    }

    public void setModifyDate(String modifyDate) {
        this.modifyDate = modifyDate;
    }

    public String getModifyUser() {
        return this.modifyUser;
    }

    public void setModifyUser(String modifyUser) {
        this.modifyUser = modifyUser;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    @FXOneToMany(fillArguments="contactId")
    public Set<SecurityContact> getSecurityContacts() {
        return this.securityContacts;
    }

    public void setSecurityContacts(Set<SecurityContact> securityContacts) {
        this.securityContacts = securityContacts;
    }


}

Sorry for being so long-winded. Anyone have any ideas?

  • 1 1 Answer
  • 0 Views
  • 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-24T08:40:55+00:00Added an answer on May 24, 2026 at 8:40 am

    That all looks fairly normal to me. I suspect the problem might be in the code that does the loading/saving/updating. I tested a trimmed-down version of your entities, and adding an audit contact to a security contact that doesn’t already have one works fine. You can take a look at the code on github, or just clone the project and run it yourself:

    git clone git://github.com/zzantozz/testbed.git tmp
    cd tmp
    mvn compile exec:java -Dexec.mainClass=rds.hibernate.MultipleManyToOnes -pl hibernate-multi-many-to-ones
    

    You may have a different problem, though. Your @OneToMany(mappedBy="agentContact") on the AgentContact class is only going to contain the SecurityContacts that have this AgentContact as their agentContact property, not any that have it as their auditContact. Also, all of that @Column(name="name with underscores") nonsense can be gotten rid of if you just use a NamingStrategy. The ImprovedNamingStrategy that ships with Hibernate already does the camel-case to underscore-separated conversion for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called records which has several columns, one of which is
I have table called articles_tags which have two columns: article_id tag_id (has_and_belongs_to_many association) (I
I have a table called CountriesList with ID and Country columns. I have another
I have a table called ApprovalTasks... Approvals has a status column I also have
I have a table called BlogPost which has a 1-to-many relationship with the Comment
Suppose I have a table called Companies that has a DepartmentID column. There's also
Right now I have a table called Campaigns that has many Hits, if I
In my oracle database I have table called PERSON with columns code, surname, forename.
I have table called emp . The table contains three columns empid , ename
I have table called Table1 with columns, col1 and col2 with col1 having weblinks

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.