Java Persistence: @ManyToMany Project to List<Projects>

24
August 22, 2019, at 11:20 AM

Trying to create a many-to-many relationship using Java Persistence annotations for the first time.

Scenario: Java class Project contains subprojects, which is just a List of Projects. There is no inverse (no superproject) member. So I thought the many-to-many relationship would be perfect for this

@ManyToMany(fetch = FetchType.EAGER, targetEntity = ProjectEntity.class, mappedBy = "project")    
@Override
public List<ProjectImpl> getSubProjects() {
    return super.getSubProjects();
}

Q1: Is this the correct way to persist a project with a list of subprojects?

Q2: Also, i am currently getting the error: mappedby reference an unknown target property. I found this highly rated thread for the error: mappedBy reference an unknown target entity property however i don't have a one one-to-many / many-to-one inverse or two different classes here

Answer 1

I guess you don't need mappedby at all, because it is not bi-directional. You probably should specify the link table that is used for the many-to-many (unless you change it to one-to-many).

READ ALSO
How do to upgrade this code as per given conditions [on hold]

How do to upgrade this code as per given conditions [on hold]

I had to write a program to achieve the following

24
swing - JTextArea and Jlabel graphical issue

swing - JTextArea and Jlabel graphical issue

When i highlight text on one of the pages it does some crazy crap

28
how to create a docker for the kafka commands Im currently using

how to create a docker for the kafka commands Im currently using

I currently have the following command list to run kafka locally:

36
dockerode, how make the process running in container independent from the node process?

dockerode, how make the process running in container independent from the node process?

I'm working on a small app utilising dockerode for the container managementI'm trying to make the process running in the docker container independent from node process

52