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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:46:15+00:00 2026-05-23T09:46:15+00:00

I have Application entity, want to express self bi-directional relationship with attribute in JPA.

  • 0

I have Application entity, want to express self bi-directional relationship with attribute in JPA.
EX. QuoteStore(provider Application) provides services to online portal and many(consumer applications)
and QuoteStore(consumer Application) consumes services from Siebel CRM and many (provider applications)
The above approach works well when relationship is ManyToMany but not self (ex. App2DB or App2BizCase)
For Self bidirectional ManyToMany relationship with attributes on application entity; I decomposed it to two OneToMany Relationships like


App 1--One2Many--* App2AppLink *--ManyToOne-1 App
(Provider 1--One2Many--* App2AppLink *--ManyToOne-1 Consumer)

Here is Application Entity

@Entity
public class ApplicationEO {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private long id;

  /**
   * This application instance services are consumed by  Set<App2AppLinkEO> applications connections/links
   */
  @OneToMany(mappedBy = "provider")
  private Set<App2AppLinkEO> consumberLinks;

  /**
   * This application instance consumes services by Set<App2AppLinkEO> applications connections/links
   */
  @OneToMany(mappedBy = "consumer")
  private Set<App2AppLinkEO> providerLinks;

}

Here is Application to Application relationship table

@Entity
@Table(name="APP2APPLINK")
public class App2AppLinkEO {

  @EmbeddedId
  @AttributeOverrides({@AttributeOverride(name = "entity1Id", column = @Column(name = "PROVIDER_ID")),
      @AttributeOverride(name = "entity2Id", column = @Column(name = "CONSUMBER_ID"))})

  private CompositePK id;

  @ManyToOne(optional = false)
    private ApplicationEO providerApp;

  @ManyToOne(optional = false)
   private ApplicationEO consumerApp;

  private String service;

  private String status;

  private String platform;
}

And Here is Composite Primary Key code

@Embeddable
public class CompositePK implements Serializable {

  private long entity1Id;

  private long entity2Id;
}

Above setup generates relation table as:

CREATE TABLE APP2APPLINK (
                          PLATFORM VARCHAR(255), 
                          STATUS VARCHAR(255), 
                          SERVICE VARCHAR(255), 
                          PROVIDER_ID BIGINT NOT NULL, 
                          CONSUMBER_ID BIGINT NOT NULL, 
                          CONSUMERAPP_ID BIGINT, 
                          PROVIDERAPP_ID BIGINT, 
                          PRIMARY KEY (PROVIDER_ID, CONSUMBER_ID))

But why do I see below extra columns there?

 CONSUMERAPP_ID BIGINT, 
 PROVIDERAPP_ID BIGINT, 
  • 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-23T09:46:15+00:00Added an answer on May 23, 2026 at 9:46 am

    You are not setting the @JoinColumn on the @ManyToOne’s so they get the default join column name. You need to give,

    @JoinColumn(name="PROVIDER_ID", insertable=false, updateable=false)
    
    @JoinColumn(name="CONSUMBER_ID", insertable=false, updateable=false)
    

    You need to mark them as read-only as you are writing the field from your EmbeddedId (or you could mark it as insertable=false, updateable=false)

    But really you should remove the EmbeddedId entirely and just add @Id to the @ManyToOne’s and define an @IdClass.

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

Sidebar

Related Questions

I have configuration entity in my .NET CF application and I want to use
I have createa simple CRUD application utilize JPA and Hibernate. I have entity annotated
I have a java application which uses JPA. Say I have an entity called
We have a Silverlight application that uses WCF Data Services. We want to add
I have created an asp.net application using Entity Framework. In this I want to
I have created a new application using Entity Framework 4.3 database migrations. The migrations
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
I have asp.net application and am using Entity Framework to connect it with the
I have a large application that uses EJB 2.x entity beans (BMP). This is
I have a WPF application with MVVM, Entity Framework and a WCF service. I

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.