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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:34:17+00:00 2026-06-07T19:34:17+00:00

I currently work on a web app using Java EE/EclipseLink and postgreSQL. About my

  • 0

I currently work on a web app using Java EE/EclipseLink and postgreSQL.
About my entities, I manage in particular “Project” , “User” and “Right” (access rights like read, write, delete…). The relationship between these entities is : a project can have multiple users who have different rights on the project. Hence, I get a triple association: Project+User+Right.

I’m facing an annoying problem during this association’s persistence. When I persist a project with its information, everything is fine (it’s in the DB and I can use it in my app), I also have persisted rights and users. Then, I want to add an association between them so I create the association entity called ProjectUserRight, I set the project, the user and the right from existing entities but when I persist it, I get the exception below :

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERREUR: une valeur NULL viole la contrainte NOT NULL de la colonne « id_project »
Error Code: 0
Call: INSERT INTO project_user_right (id_right, id_project, id_user) VALUES (?, ?, ?)
bind => [3 parameters bound]
Query: InsertObjectQuery(ProjectUserRight@192db555)

Here is the class Project :

@Entity
@Table(name="project")
public class Project implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id_project", unique=true, nullable=false)
private Integer idProject;


   //bi-directional many-to-one association to ProjectUserRight
@OneToMany(mappedBy="project", cascade={CascadeType.ALL})
private Set<ProjectUserRight> projetUtilDroits;


  ...

The class User :

 @Entity
 @Table(name="user")
 public class User implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id_user", unique=true, nullable=false)
private Integer idUser;


@Column(name="nom_utilisateur", nullable=false, length=50)
private String userName;

   //bi-directional many-to-one association to ProjectUserRight
@OneToMany(mappedBy="user")
private Set<ProjectUserRight> projetUtilDroits;

   ...

The class Right :

   @Entity
   @Table(name="right")
   public class Right implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id_right", unique=true, nullable=false)
private Integer idRight;

@Column(name="type_right", nullable=false, length=10)
private String typeRight;

//bi-directional many-to-one association to ProjectUserRight
@OneToMany(mappedBy="right")
private Set<ProjectUserRight> projetUtilDroits;

    ...

And the association class :

 @Entity
 @Table(name="project_user_right")
 public class ProjectUserRight implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private ProjectUserRightPK id;

//bi-directional many-to-one association to Right
    @ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH})
@JoinColumn(name="id_right", insertable=false, updatable=false)
private Right right;

//bi-directional many-to-one association to Project
@ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH})
@JoinColumn(name="id_project", insertable=false, updatable=false)
private Project project;

//bi-directional many-to-one association to User
@ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH})
@JoinColumn(name="id_user", insertable=false, updatable=false)
private User user;

And the ProjectUserRightPK (edited after comment) :

@Embeddable
public class ProjectUserRightPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;

@Column(name="id_project", unique=true, nullable=false)
private Integer idProject;

@Column(name="id_right", unique=true, nullable=false)
private Integer idRight;
    ...//getters and setters
@Column(name="id_user", unique=true, nullable=false)
private Integer idUser;

I wrote the following code to persist the association:

 Project project = getService(Projet.class).getFromID(projectId);//retrieve the existing project from database with id

 User user = getService(Utilisateur.class).getFromID(userId);//retrieve the existing user from database with id

 Right right = getService(Right.class).getFromID(rightId);//retrieve the existing right from database with id
 if(project !=null && user!=null && right!=null){
   ProjectUserRight pud = new ProjectUserRight();
   pud.setRight(right);
   pud.setProject(project);
   pud.setUser(user);
   project.getProjectUserRights().add(pud);
   right.getProjectUserRights().add(pud);
   user.getProjectUserRights().add(pud);
   service(ProjetUtilDroit.class).persist(pud);//call the persist function on this entity (works fine with all other entities)
   }

I also tried to merge the project instead of persisting the association but I get the same error… (I also checked the id project and it is properly set) I’m wondering if it’s the association which is wrongly annotated but I can’t find the proper way to change it.

So, I really need your help! 🙂

Thanks in advance for your advice!

  • 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-07T19:34:18+00:00Added an answer on June 7, 2026 at 7:34 pm

    You missed the @MapsId annotation:

    Designates a ManyToOne or OneToOne relationship attribute that
    provides the mapping for an EmbeddedId primary key, an attribute
    within an EmbeddedId primary key, or a simple primary key of the
    parent entity. The value element specifies the attribute within a
    composite key to which the relationship attribute corresponds.

    @MapsId("idRight")
    @ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name="id_right")
    private Right right;
    
    @MapsId("idProject")
    @ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name="id_project")
    private Project project;
    
    @MapsId("idUser")
    @ManyToOne(cascade={CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name="id_user")
    private User user;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using the Owasp ESAPI to manage authentication in my java web
I currently work on a tracking project using a GPS receiver and a modem
I'm currently using Handlebars.js (associated with Backbone and jQuery) to make a web app
I'm currently working on a simple web project, for which I am using the
I´m currently building a web radio streaming app using the BackgroundAudioPlayer. The problem is
i'm currently working in a web app and i'm using django-jquery, and when i
I'm currently building a new web app, in Java EE with Apache Tomcat as
Our development team uses Eclipse + Aptana to do their web development work. Currently,
I'm currently working on a web application development. Our company methodology is to work
I am working with google app engine and using the low leval java api

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.