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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:20:22+00:00 2026-05-26T10:20:22+00:00

I am trying to setup a 1to0..1 (zero or one) relationship, but am running

  • 0

I am trying to setup a 1to0..1 (zero or one) relationship, but am running into issues.

Now my assumption is to use the @OneToMany, and not @OneToOne.

Basically I want my “child” table to hold the foreign key to the “parent” (I use child and parent very loosely). I never need to load “children” standalone

This is the basic table structure I want to achieve

ITEM {
  ID
  RELATED_ITEM_ID
}

INVOICE {
  ID
}
CATALOGUE {
  ID
}

Reprsented as Java classes like the following

class Item {
...
}

class Invoice {
  @OneToMany(fetch=FetchType.EAGER, orphanRemoval = true, cascade = { javax.persistence.CascadeType.ALL })
  @Fetch(FetchMode.JOIN)
  @JoinColumn(name="RELATED_ITEM_ID", nullable=false)
  Set<Item> items;
}

class Catalogue {
  @OneToMany(fetch=FetchType.EAGER, orphanRemoval = true, cascade = { javax.persistence.CascadeType.ALL })
  @Fetch(FetchMode.JOIN)
  @JoinColumn(name="RELATED_ITEM_ID", nullable=false)
  Set<Item> items;
}

The above code, if I only have Invoice or Catalogue registered in hibernate will create the tables as I want, and work perfectly. However, as soon as I have both Invoice and Catalogue registered, hibernate throws me the error

org.hibernate.MappingException: Duplicate property mapping of _itemsBackref found in package.name.Item
  • 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-26T10:20:23+00:00Added an answer on May 26, 2026 at 10:20 am

    I sort of ended up cheating to get this to work how I want. I dont ideally want a hierachy like that, but I need to get this working, and I feel this is a compromise with working around hibernate.

    ITEM {
      ID
      RELATED_ITEM_ID
      DTYPE
    }
    
    INVOICE {
      ID
    }
    
    CATALOGUE {
      ID
    }
    

    Reprsented as Java classes like the following

    @Entity
    @Table(name="RECIPIENTS")
    abstract class Item {
      ...
    }
    
    @Entity
      public class InvoiceItem extends Item {
    }
    
    @Entity
      public class CatalogueItem extends Item {
    }
    
    
    class Invoice {
      @OneToMany(fetch=FetchType.EAGER, orphanRemoval = true, cascade = { javax.persistence.CascadeType.ALL })
      @Fetch(FetchMode.JOIN)
      @JoinColumn(name="RELATED_ITEM_ID", nullable=false)
      Set<InvoiceItem> items;
    }
    
    class Catalogue {
      @OneToMany(fetch=FetchType.EAGER, orphanRemoval = true, cascade = { javax.persistence.CascadeType.ALL })
      @Fetch(FetchMode.JOIN)
      @JoinColumn(name="RELATED_ITEM_ID", nullable=false)
      Set<CatalogueItem> items;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to setup to use the Geospatial Index on MongoDB, I run into
I'm trying to setup CruiseControl.net at the moment. So far it works nice, but
I'm trying setup costum storege. Looks like all is ok. But there is the
In trying to setup a unit test for inserting an item into an SQL
I am trying to setup Django to use MySQL. I am getting the following
im trying to setup two listeners for one button. Here is my code: This
Been trying to setup my Facebook app which I want to use for Logins
I m trying setup a cassandra cluster as a test bed but gave the
Trying to setup SVN to use HTTP, with the user/auth user access files. I
im trying to setup sqlite as a secondary adapter and have run into a

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.