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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:43:04+00:00 2026-06-11T00:43:04+00:00

I have a model objects relationship such as this: @Table(name=cables) class Cable { @Id

  • 0

I have a model objects relationship such as this:

@Table(name="cables")
class Cable {
    @Id
    private Long id;
    @Column(name="dstport_id")
    private Port dstPort;
    @Column(name="srcport_id")
    private Port srcPort;
}
@Table(name="ports")
class Port {
    @Id
    private Long id;
    private Cable cable; // Here's the mapping that should point to cables.dstport_id or cables.srcport_id whatever is present
}

In this relationship the mapping is a One-to-One mapping through Cable’s dstport_id OR srcport_id columns. A cable could be connected to none, one or two (exclusively different) ports. A Port could be connected to none or only one cable and to it’s either endpoint. So, is there a way in Hibernate to map such a relationship inside the Port entity (there’s no tricks to map it inside the Cable entity)?

  • 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-11T00:43:05+00:00Added an answer on June 11, 2026 at 12:43 am

    I don’t believe it is possible to define the relationship from Port to Cable with only one association in Port.

    In my view, your best option would be to define 2 optional, one-to-one associations to Cable in Port (dstPortCable and srcPortCable, say) using the ‘mappedBy’ joining method, and then define a method in Port, thus:

    public Cable getCable() {
        if (dstPortCable != null) {
            return dstPortCable;
        }
        if (srcPortCable != null) {
            return srcPortCable;
        }
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some model objects that resemble this: public class FooModel {
I have a parent-child relationship: @Entity @Table(name = user) public final class User {
I have two objects of the same class (Model) type. I want to check
I have a handful of DBIx::Class::Core objects that model various database tables. For some
I have a model that has a unique generic foreign key relationship: class Contact(models.Model):
If I have two objects that have a many-to-many relationship, I would typically model
I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
If I have Model.objects.all() I want to get only one object for any content_object=foo,
In our ColdFusion application we have stateless model objects. All the data I want

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.