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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:34:12+00:00 2026-06-17T17:34:12+00:00

I have two entities Item . They are linked with entity Link Each item

  • 0

I have two entities Item.

They are linked with entity Link

Each item can have many links, but link is a connection between two items.

The problem is that the order of items is important. One is always the first item and other is second item.

So my entities are like this:

Item
   private Collection<Link> links = new ArrayList<Link>();
    @OneToOne(cascade = CascadeType.ALL, mappedBy = ????)
    public Collection<Link> getLinks() {
       return links;
   }

Link
private Item firstItem;
private Item secondItem;

@OneToOne(mappedBy = ???)
public Item getFirstItem() {
    return firstItem;
}

@OneToOne(mappedBy = ???)
public Item getSecondItem() {
    return secondItem;
}

What should i put to mappedBy?? Because pseudomapping for Item should me smthin like this:
mappedBy = { "firstItem", "secondItem") }

At first I had no mapping and this gives error:

 @OneToOne or @ManyToOne on foo.bar.Item.links references an unknown entity: java.util.Collection
  • 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-17T17:34:13+00:00Added an answer on June 17, 2026 at 5:34 pm

    You have to create two different collections with mappedBy pointing to firstItem and secondItem, respectively.

    If you need to view them as a single collection, do it in code.

    Also as already noted you need to use @OneToMany/@ManyToOne instead of @OneToOne. @ManyToOne doesn’t need mappedBy.

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

Sidebar

Related Questions

i have two Entities, Parent and Child, that are linked through a bidirectional one-to-many
I have the following core data model with two entities: entity item which holds
I currently have two entities, a category entity and an item entity, where Category:Item
I have 2 entities Locations and Items. Many to many relationship. So each item
I've got two entities, Item and City. How can I model like a one-to-many
I have two entities Foo and Bar with a Many to Many relationship between
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities: Patient and Job. Patient has a to-many relationship to Job
I have two entities types: RunContainer parent entity type Run child entity type Run
I have a class called Entity, with two child classes: Creature and Item. (I'm

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.