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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:50:47+00:00 2026-05-25T23:50:47+00:00

I have a domain class called Flight that represents a flight that has been

  • 0

I have a domain class called Flight that represents a flight that has been flown. I have another class called Movement which can represents either a departure or an arrival and contains a date and time and the airport at which the movement occured.

@Entity
public class Flight implements Serializable {

    private Movement departure;
    private Movement arrival;
}

@Entity
public class Movement implements Serializable {
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateTime;
    @ManyToOne
    private Airport airport;

    private Flight flight;
}

I am however not sure how to properly annotate the flight field in the Movement class. I figured the Flight class has to be the owning side of the relationship because if it is not, there is no way to tell if the Movement of a specific Flight was the departure or the arrival:

@OneToOne
private Movement departure;
@OneToOne
private Movement arrival;

This, however, poses a problem. I can’t map the flight field in the Movement class on both fields:

// This obviously does not work
@OneToOne(mappedBy = "departure")
@OneToOne(mappedBy = "arrival")
private Flight flight;

How would I go about properly annotating this, having both the departure and arrival field properly reference the Movement and still be able to have the flight field on the Movement class reference the Flight class?

  • 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-25T23:50:48+00:00Added an answer on May 25, 2026 at 11:50 pm

    If you really need a bidirectional relationship, then you’ll need to have to fields in movement, with one of them always being null:

    @OneToOne(mappedBy = "departure")
    private Flight departureFlight;
    
    @OneToOne(mappedBy = "arrival")
    private Flight arrivalFlight;
    

    But you could have a single getter:

    public Flight getFlight() {
        return departureFlight == null ? arrivalFlight : departureFlight;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a domain class called Order and that class has hasMany relation with
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
I've got a class called Domain. Each Domain can have multiple sub-domains (of the
I have a class in my domain model called JobPlan this class is stored
I have a domain class containing a couple of fields. I can access them
Here is the domain that I wish to have: public class Person { public
Let's say I have a domain class called ShopCategoryPageTab. And I have a domain
In our Core domain model design, we have got a class called Category whose
Let's say I have a multitenant app with a domain class called Store. Each
So let's say we have a domain object such as the following public class

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.