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 9273383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:06:08+00:00 2026-06-18T16:06:08+00:00

In the Spring/Hibernate/Java/Tomcat app I’m writing I have a OneToMany relationship between an Organization

  • 0

In the Spring/Hibernate/Java/Tomcat app I’m writing I have a OneToMany relationship between an Organization and its Contacts.

Organization 1:M Contact (has foreign key org_id)

In Organization I have this field:

@OneToMany(mappedBy="organization")
private List<Contact> contacts;

In Contact I have this field:

@ManyToOne
@JoinColumn(name="org_id")
private Organization organization;

All is working OK so far. Now I’m adding the concept of an Offer. The Offer can be made by an Organization, and you speak with the designated Contact for that particular Offer.

Offer has foreign keys for its organization (org_id) and designated contact (contact_id).

So far, the Offer would look like:

@OneToOne
@JoinColumn(...)
private Organization offering_org;

@OneToOne
@JoinColumn(...)
private Contact offering_contact;

Here comes the point of my question. I’ve already annotated the Contact class for use with Organization. If I try to persist the Offer object in the usual Hibernate way, I’ll need to store copies of an Organization object and a Contact object into the Offer object. This seems to conflict with my existing Organization : Contact use of the two Java classes. For example, if I’ve a 1:1 with Offer, if I put this into the Contact class do I get an optional use of either or a mandatory simultaneous use of both?

Since the Offer is yet another relationship, do I need to write a data transfer object version of Contact for use in the Offer relationship?

Thanks,
Jerome.

  • 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-06-18T16:06:09+00:00Added an answer on June 18, 2026 at 4:06 pm

    I’m thinking that my original question is kind of stupid. What I did try is to put this in Offer.java:

    @Column(name="org_id")
    private Long orgId = null;
    
    @Column(name="contact_id")
    private Long contactId = null;
    

    I fill orgId manually because an offer is always tied to the user’s Organization. It is a hidden field in the web page.

    I put a SELECT filled with appropriate Contact objects (contact.id, contact.name) in the web page.

    When the web page is submitted the Offer’s orgId and contactId fields are filled in the @ModelAttribute parameter. This takes me where I want to go.

    To address the comments of Mr. mspringer, your example could work (you illustrated a “create new” situation) if I were willing to use an Organization or Contact list in my Offer object. It is also somewhat the topic of my original question. But since I see that I don’t really want to play with the expanded objects within Offer, nor do I wish to, I can avoid the topic of my original question.

    Thanks to all who looked at my exercise in confusion.

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

Sidebar

Related Questions

I have a java web app running under Spring 2.5.6, Hibernate 3.4 (with Hibernate
I have a web-application in java, spring framework, hibernate on tomcat, that has basically
When I look at Java frameworks like Hibernate, JPA, or Spring, I usually have
I'm writing some simple DAOs in Java using JDBC (no Spring, Hibernate or anything
We run a Spring 3.1/Hibernate 4/Java 7/Tomcat 7/MSSQL 2008 R2 web application. We must
I have an spring-hibernate web application running on tomcat server version 7.0.25 with jdk
Background: I have a Spring 2.5/Java/Tomcat application. There is the following bean, which is
We have a Java web application that uses Spring and Hibernate and has a
We have a j2ee/spring/hibernate/tomcat web application already running on production. We are planning to
I have a web app with Spring, Hibernate and Struts 2 and I get

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.