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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:38:36+00:00 2026-06-07T21:38:36+00:00

I am building a library that directly exposes entities within a persistence unit via

  • 0

I am building a library that directly exposes entities within a persistence unit via a REST interface, to be included into a JAX-RS or standard web application.

In order to facilitate the usability of this library, I want the library itself to manage the setting/unsetting of bi-directional associations when necessary, in order to make the persistence and modification of complex entity relationships possible using simple state representations.

As an example, consider the typical ‘Project and Employee’ model, and suppose that there is a one-to-many relationship from Project to Employee – a Project can contain multiple Employee entities, and an Employee may only ‘belong’ to one Project at a time.

Also suppose that this relationship is bi-directional – Employee has a project property, and Project has a employees property that returns a collection of Employee entities who currently ‘belong’ to the Project. The properties Employee.project and Project.employees map the two sides of the bi-directional association.

Consider the following url:

PUT /Project/1/employees

And the accompanying (JSON) state representation

//Employee representation
{
   firstName: "some", 
   lastName:  "guy",
   salary: 1000000.01,
   ...
   ...
}

This URL/state representation combo directs my library to construct and add the Employee entity to the Project.employees collection of the Project whose identification property yields the value ‘1’.

What I need to be able to do is, given the standard Metamodel API, determine if Employee has some property that fulfills the bi-directional side of this association, if one exists, so that I can set that property to the Project entity in question.

In other words, I need to be able to determine that Employee has a Employee.project property that satisfies the bi-directional component of the Project.employees association.

So the state/URL combination essentially performs the following task:

EntityManager em = ....;

//this is the Employee represented by the state representation    
Employee employee = ..... ;

Object id = 1;
Project project = em.find( Project.class, id );
project.getPersons().add( employee );

I need to know when to do the following

employee.setProject( project );

My current implementation relies on a custom annotation that mimics the ‘mapped-by’ attribute in JPA 2.0 mappings, and I have planned to implement checks for the ‘mapped-by’ attribute value in JPA 2.0 annotations. This works BUT, it requires proprietary configuration ( which I am trying to get rid of ), or JPA 2.0 annotations (what if someone exclusively uses mapping files?).

If anyone can point me in the right direction towards determining the properties involved in both sides of a bi-directional association when given the Entity java type and the Metamodel API, it would be most appreciated.

  • 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-07T21:38:39+00:00Added an answer on June 7, 2026 at 9:38 pm

    I’ve come to the conclusion that there is no way to obtain such bidirectional data from the standard Persistence Metamodel. I’ve solved by my problem by using existing JPA 2.0 annotations, falling back to a custom @Bidirectional annotation if XML mapping is being used.

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

Sidebar

Related Questions

I'm building an Authentification library that's going to have around 45+ methods for dealing
I am building a C++ application that uses Intel's IPP library. This library is
I'm building a basic CRUD library, that I anticipate use in both local (add
I am building a library that will be used in several Python applications. It
I'm building a js library that reads binary files, including zip files. Because there's
I'm building a python library that implements a task queue. If for whatever reason
I am successfully building a shared library that is C++ and loading it in
I'm building a class library that will have some public & private methods. I
I am building a DLL library that uses OpenCV 2.3. I am using this
I have a static library that I am building in C++. I have separated

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.