Seeing "referencedColumnNames(ID) ... not mapped to a single property" error with a 1-M relationship after adding a composite key to the "1" side - jpa

I have an existing JPA entity ("Reference") with an ID column as its primary key that it inherits from a base class "BaseEntity" (using the #MappedSuperclass annotation on the superclass).
I also have a 1-M relationship between a Reference and another entity called Violation. Violation was previously defined with a foreign key "REFERENCE_ID" to the "ID" column of the Reference entity.
Recently, I tried to add an unrelated composite key to the Reference entity. This should not have affected the 1-M relationship between Reference and Violation. However, when I run the code in my tomcat server, I see the following stack trace:
Caused by: org.hibernate.AnnotationException: referencedColumnNames(ID) of org.qcri.copydetection.sdk.metastore.entity.Violation.reference referencing org.qcri.copydetection.sdk.metastore.entity.Reference not mapped to a single property
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:205) ~[hibernate-annotations-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:110) ~[hibernate-annotations-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:541) ~[hibernate-annotations-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:523) ~[hibernate-annotations-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:380) ~[hibernate-annotations-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206) ~[hibernate-core-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1459) ~[hibernate-entitymanager-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193) ~[hibernate-entitymanager-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1086) ~[hibernate-entitymanager-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:685) ~[hibernate-entitymanager-3.5.6-Final.jar:3.5.6-Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73) ~[hibernate-entitymanager-3.5.6-Final.jar:3.5.6-Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
... 39 common frames omitted
Here is the code for the 3 classes involved:
#Entity
#Table(name = "REFERENCE")
#XmlRootElement
#XmlAccessorType(XmlAccessType.PROPERTY)
#IdClass(Reference.ContextualName.class)
public class Reference extends BaseEntity {
#Column(name= "LOCATION", unique=true)
#XmlElement
private String location;
#Id
#AttributeOverrides({
#AttributeOverride(name = "name", column = #Column(name = "NAME")),
#AttributeOverride(name = "account", column = #Column(name = "ACCOUNT_ID"))
})
#Column(name = "NAME")
#XmlElement
private String name;
#ManyToOne(optional=false)
#XmlTransient
#JoinColumn(name = "ACCOUNT_ID", referencedColumnName = "ID")
private Account account;
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Reference() {}
public Reference(String name) {
setName(name);
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public Account getAccount() {
return this.account;
}
public void setAccount(Account account) {
this.account = account;
}
#Embeddable
private class ContextualName implements Serializable {
private static final long serialVersionUID = -3687389984589209378L;
#Basic(optional = false)
#Column(name = "NAME")
#XmlElement
private String name;
#ManyToOne(optional=false)
#XmlTransient
#JoinColumn(name = "ACCOUNT_ID", referencedColumnName = "ID")
private Account account;
ContextualName() {}
}
}
#MappedSuperclass
#XmlAccessorType(XmlAccessType.FIELD)
public abstract class BaseEntity {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "ID")
#XmlElement
private Long id;
#Basic(optional = true)
#Column(name = "CREATED", insertable = false, updatable = false, columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
#Temporal(TemporalType.TIMESTAMP)
#XmlElement
private Date creationDate;
protected BaseEntity() {}
public Long getId() {
return id;
}
public void setId(Long id) {
if(this.id==null) {
this.id = id;
} else if (this.id!=id) {
throw new IllegalArgumentException("Cannot change the id after it has been set, as it is a generated field.");
}
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
if(this.creationDate==null) {
this.creationDate = creationDate;
} else if (this.creationDate!=creationDate) {
throw new IllegalArgumentException("Cannot change the creation-date after it has been set, as it is a generated field.");
}
}
}
#Entity
#Table(name = "VIOLATION")
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
public class Violation extends BaseEntity {
#ManyToOne (optional=false, fetch= FetchType.EAGER)
#JoinColumn(name = "REFERENCE_ID", referencedColumnName = "ID")
private Reference reference;
#ManyToOne (optional=false, fetch= FetchType.EAGER)
#JoinColumn(name = "SUSPECT_ID", referencedColumnName = "ID")
private Suspect suspect;
#ManyToOne (optional=false, fetch= FetchType.EAGER)
#XmlTransient
#JoinColumn(name = "SEARCH_ID", referencedColumnName = "ID")
private Search search;
#Basic(optional = false)
#Column(name = "SCORE")
#XmlElement
private double score;
public Violation() {}
public Violation(Search search, Reference ref, Suspect sus, double score) {
this.search = search;
this.reference = ref;
this.suspect = sus;
this.score = score;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public Reference getReference() {
return reference;
}
public void setReference(Reference reference) {
this.reference = reference;
}
public Suspect getSuspect() {
return suspect;
}
public void setSuspect(Suspect suspect) {
this.suspect = suspect;
}
public Search getSearch() {
return search;
}
public void setSearch(Search search) {
if(this.search!=null && this.search!=search) {
this.search.removeViolation(this);
}
this.search = search;
if(search!=null) {
if(!search.getViolations().contains(this)) {
search.addViolation(this);
}
}
}
}
To cut a long story short, I'm totally confused how to go about adding a composite key to an existing (legacy) entity that already has an ID column. I can't remove the ID column, nor can I change the 1-M relationship between Reference and Violation. I can't for the life of me understand the error message because the "REFERENCE_ID" foreign key column of the Violation entity is being mapped to a single "ID" column of the Reference entity.
Many thanks in advance!

Related

ManyToOne and OneToMany is giving stackoverflow error

Project is based on JPA persistance with two Entities (Deaprtment and Employee)
Department(OneToMany) and Employee(ManyToOne)
Whenever I send a request via API there's a StackOverFlow error. So far I back Traced the main cause which is the stack is full is indefinite recursion. Could someone explain why this happened ususally it shouldn't have confused by bidirectioanl relationship of entities.
package com.springjpacrud01.model;
import javax.persistence.*;
import java.util.List;
#Entity
#Table(name = "department")
public class Department {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
#Column(name = "name")
private String name;
#OneToMany(mappedBy = "department", fetch = FetchType.LAZY)
List<Employee> employees;
public Department() { }
public Department(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Employee> getEmployees() {
return employees;
}
public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
}
import com.fasterxml.jackson.annotation.JsonBackReference;
import javax.persistence.*;
#Entity
#Table(name = "employees")
public class Employee {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(name = "name")
private String name;
#Column(name = "position")
private String position;
#ManyToOne
#JoinColumn(name = "department_id")
private Department department;
public Employee(Long id, String name, String position) {
this.id = id;
this.name = name;
this.position = position;
}
public Employee() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
}
After I just deleted the getters/setters from the Department entity it worked but
it shouldn't have work like that and I want why I cannot do relation pointing to each other entities? It couldn't form JSON response because of the infinite recursion of pointing to each other I guess. How can I solve it effectively in order to retrieve Employees by department ID, thank you)
If someone needs it I've solved this by understanding the deep root of the cause which was #JoinColumn created and addressed by Hibernate to that empty common column which I deleted manually. And when I was requesting the department_id of the employee via the employee repository Hibernate sort of got stuck in an infinite loop of going to the employee repository and from there to the department repository and in the department repository going to the employee repository. To stop that I've mapped the relation differently by making a configuration of the department
#OneToMany(mappedBy = "department", cascade= CascadeType.ALL, orphanRemoval=true) private Set<Employee> employeeHashSet = new HashSet<>();
And
#ManyToOne
#JoinColumn(name = "department_id")
private Department department;

JPA- insert a ID of parent to child table

when there is a many to one associate between two object in hibernate(JPA) and we want insert a ID of parent to child table without new record in parent table how do I implement it?
#ManyToOne(targetEntity = RoleEntity.class,cascade = CascadeType.ALL,fetch = FetchType.LAZY)
#JoinColumn(name = "FK_ROLE_ID",referencedColumnName = "ID")
private RoleEntity role;
I write this:
UserEntity userEntity=new UserEntity();
userEntity.setUserName(username);
userEntity.setPassword(password);
userEntity.setCreatedDate(new Date().toString());
RoleEntity roleEntity=new RoleEntity();
roleEntity.setTitle("user");
userEntity.setRole(roleEntity);
but the last three line also insert a new record in user table.
This completely of roleEntity:
package Entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* Created by Mohsen on 7/10/2018.
*/
#Entity(name = "role")
#Table(name = "ROLE")
public class RoleEntity implements Serializable {
#Id
#Column(name = "ID")
#SequenceGenerator(name = "SEQ_ROLE", sequenceName = "SEQ_ROLE", allocationSize = 1)
#GeneratedValue(generator = "SEQ_ROLE", strategy = GenerationType.SEQUENCE)
private int id;
#Basic
#Column(name = "Title")
private String title;
// #OneToMany(targetEntity = UserEntity.class,cascade = CascadeType.ALL,fetch = FetchType.LAZY)
// #JoinColumn(name = "FK_ROLE_ID",referencedColumnName = "ID")
// private Set<UserEntity> user;
public RoleEntity() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
This completely of userEntity:
package Entity;
import javax.persistence.*;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Mohsen on 7/10/2018.
*/
#Entity(name = "user")
#Table(name = "USERR")
public class UserEntity implements Serializable {
#Id
#Column(name = "ID")
#SequenceGenerator(name = "SEQ_USER", allocationSize = 1, sequenceName = "SEQ_USER")
#GeneratedValue(generator = "SEQ_USER", strategy = GenerationType.SEQUENCE)
private int id;
#Basic
#Column(name = "UserName", columnDefinition = "VARCHAR2(20 CHAR)")
private String userName;
#Basic
#Column(name = "Password", columnDefinition = "VARCHAR2(255 CHAR)")
private String password;
#Basic
#Column(name = "CreatedDate")
private String createdDate;
#Basic
#Column(name = "EndedDate")
private String endedDate;
#OneToOne(targetEntity = PeopleEntity.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private PeopleEntity people;
#ManyToOne(targetEntity = RoleEntity.class,cascade = CascadeType.ALL,fetch = FetchType.LAZY)
#JoinColumn(name = "FK_ROLE_ID",referencedColumnName = "ID")
private RoleEntity role;
public RoleEntity getRole() {
return role;
}
public void setRole(RoleEntity role) {
this.role = role;
}
public UserEntity() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCreatedDate() {
return createdDate;
}
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
public String getEndedDate() {
return endedDate;
}
public void setEndedDate(String endedDate) {
this.endedDate = endedDate;
}
public PeopleEntity getPeople() {
return people;
}
public void setPeople(PeopleEntity people) {
this.people = people;
}
}
I have found the solution
I set cascade = CascadeType.REMOVE in child object and it works

Jpa Auditing dont save data in table auditing

I have to implementes Auditing in my aplication.. i inserting this data correctly
but i want to save all atributter from my Entity ,
Exemple, name, epigrafe, .. and olthers.
I implemented the mothod but dosent work, just dont save the atributte..
lets see..
#Entity
#EntityListeners(AuditingEntityListener.class)
#Table(name = "logradouros_historico", schema = "aud")
public class LogradourosHistorico {
#Id
#GeneratedValue
private Long id;
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "id_logradouro")
private Logradouros logradouro;
#CreatedBy
private String modificadoPor;
#CreatedDate
#Temporal(TemporalType.TIMESTAMP)
private Date modifiedDate = new Date();
#Enumerated(EnumType.STRING)
private Acoes acao;
#Column(name = "nome")
private String nome; //nome do logradouro
public LogradourosHistorico() {
super();
}
public LogradourosHistorico(Logradouros logradouro, String modificadoPor,
Acoes acao) {
super();
this.logradouro = logradouro;
this.modificadoPor = modificadoPor;
this.acao = acao;
}
//getters and setters
my class entityListner
public class LogradourosEntityListener {
#PostPersist
public void prePersist(Logradouros target) {
perform(target, Acoes.INSERTED);
}
#PreUpdate
public void preUpdate(Logradouros target) {
perform(target, Acoes.UPDATED);
}
#PreRemove
public void preRemove(Logradouros target) {
perform(target, Acoes.DELETED);
}
#Transactional()
private void perform(Logradouros target, Acoes acao) {
target.getNome();
EntityManager entityManager = BeanUtil.getBean(EntityManager.class);
entityManager.persist(new LogradourosHistorico(target, acao));
}
}
my class Logradouros
#Entity
#EntityListeners(LogradourosEntityListener.class)
#Table(name = "logradouros", schema = "glb", uniqueConstraints= #UniqueConstraint(columnNames={"id_entidade", "idLogradouro"}))
public class Logradouros extends Auditable<String> implements Serializable {
private static final long serialVersionUID = 3703309412387185484L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int idLogradouro;
#Column(name = "cep_geral")
private String cepGeral;
#Column(name = "epigrafe")
private String epigrafe;
#NotNull
#Column(name = "nome")
private String nome;
#Column(name = "nome_exibicao")
private String nomeExibicao;
#JoinColumn(name = "id_entidade")
#ManyToOne(/*cascade = CascadeType.ALL*/)
private Entidades entidade;
#NotNull
#JoinColumn(name = "id_municipio")
#ManyToOne(/*cascade = CascadeType.ALL*/)
private Municipios municipio;
// gettrs and settrs
so what i did wrong because i cant get the nome of entity Logradouros

JPA Entity Mappings between two tables

I keep getting the following error with my Entity mappings.
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: edu.indstate.ics.transcript.web.dao.entity.Swrhxml.swbhxml in edu.indstate.ics.transcript.web.dao.entity.Swbhxml.swrhxmls
I am not sure what I am doing wrong. Could use some insight and help on what I am missing here.
My Entity classes are as follows:
#Entity
#Table(name = "SWBHXML" )
public class Swbhxml implements DatabaseObject, Serializable {
private List<Swrhxml> swrhxmls;
private static final long serialVersionUID = 1L;
private Long swbhxmlTransId;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "SWBHXML_TRANS_ID", nullable = false)
public Long getSwbhxmlTransId() {
return swbhxmlTransId;
}
public void setSwbhxmlTransId(Long swbhxmlTransId) {
this.swbhxmlTransId = swbhxmlTransId;
}
#OneToMany(mappedBy = "swbhxml", cascade = CascadeType.ALL)
public List<Swrhxml> getSwrhxmls() {
return swrhxmls;
}
public void setSwrhxmls(List<Swrhxml> swrhxmls) {
this.swrhxmls = swrhxmls;
}
}
#Entity
#Table(name = "SWRHXML" )
public class Swrhxml implements DatabaseObject, Serializable {
private Swbhxml swbhxml;
private static final long serialVersionUID = 1L;
private Long SwrhxmlTransId;
private String SwrhxmlHxpsCode;
private Date SwrhxmlTimeStamp;
#ManyToOne(fetch = FetchType.EAGER)
#JoinColumn(name="SWBHXML_TRANS_ID")
public Swbhxml getSwrhxml() {
return swbhxml;
}
public void setSwrhxml(Swbhxml swbhxml) {
this.swbhxml = swbhxml;
}
#Column(name = "SWRHXML_HXPS_CODE", length = 15)
public String getSwrhxmlHxpsCode() {
return SwrhxmlHxpsCode;
}
public void setSwrhxmlHxpsCode(String SwrhxmlHxpsCode) {
this.SwrhxmlHxpsCode = SwrhxmlHxpsCode;
}
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "SWRHXML_TIMESTAMP", nullable = false)
#Temporal(TemporalType.TIMESTAMP)
public Date getSwrhxmlTimeStamp() {
return SwrhxmlTimeStamp;
}
public void setSwrhxmlTimeStamp(Date SwrhxmlTimeStamp) {
this.SwrhxmlTimeStamp = SwrhxmlTimeStamp;
}
}
You use
`mappedBy = "swbhxml"`
^
|___ b here
, but the annotated association is
Swbhxml getSwrhxml()
^
|___ r here
Your getter and setter are named incorrectly. And frankly, with such cryptic and close entity names, you'll probably have many such bugs.

A Foreign key refering has wrong number of columns

I got a problem with JPA and ManyToMany association.
I got two class FOA_PARAM_EMPLOYE and FOA_PARAM_POSITION, and an association table FOA_PARAM_EMPLOYE_POSITION.
Class FoaParamEmploye :
#Entity
#Table(name = "FOA_PARAM_EMPLOYE")
#NamedQuery(name = "FoaParamEmploye.findAll", query = "SELECT f FROM FoaParamEmploye f")
public class FoaParamEmploye implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
private FoaParamEmployePK id;
#Column(name = "ACTEUR_MAJ_OCCUR")
private String acteurMajOccur;
#Column(name = "ADRESSE_EMAIL")
private String adresseEmail;
// bi-directional many-to-many association to FoaParamPosition
#ManyToMany
#JoinTable(
name = "FOA_PARAM_EMPLOYE_POSITION",
joinColumns = { #JoinColumn(name = "ID_EMPLOYE"),
#JoinColumn(name = "COD_ENTREP") },
inverseJoinColumns = { #JoinColumn(name = "ID_POSITION")
})
private List<FoaParamPosition> foaParamPositions;
public FoaParamEmployePK getId() {
return this.id;
}
public void setId(FoaParamEmployePK id) {
this.id = id;
}
public String getActeurMajOccur() {
return this.acteurMajOccur;
}
public void setActeurMajOccur(String acteurMajOccur) {
this.acteurMajOccur = acteurMajOccur;
}
public String getAdresseEmail() {
return this.adresseEmail;
}
public void setAdresseEmail(String adresseEmail) {
this.adresseEmail = adresseEmail;
}
public List<FoaParamPosition> getFoaParamPositions() {
return foaParamPositions;
}
public void setFoaParamPositions(List<FoaParamPosition> pFoaParamPositions) {
this.foaParamPositions = pFoaParamPositions;
}
}
Class FoaParamPosition :
#Entity
#Table(name="FOA_PARAM_POSITION")
#NamedQuery(name="FoaParamPosition.findAll", query="SELECT f FROM FoaParamPosition f")
public class FoaParamPosition implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
private FoaParamPositionPK id;
#Column(name="ACTEUR_MAJ_OCCUR")
private String acteurMajOccur;
#Column(name="CD_PROFIL_AFFECTATION")
private String cdProfilAffectation;
// bi-directional many-to-many association to FoaParamEmploye
#ManyToMany
private List<FoaParamEmploye> foaParamEmployes;
public FoaParamPositionPK getId() {
return this.id;
}
public void setId(FoaParamPositionPK id) {
this.id = id;
}
public String getActeurMajOccur() {
return this.acteurMajOccur;
}
public void setActeurMajOccur(String acteurMajOccur) {
this.acteurMajOccur = acteurMajOccur;
}
public String getCdProfilAffectation() {
return this.cdProfilAffectation;
}
public void setCdProfilAffectation(String cdProfilAffectation) {
this.cdProfilAffectation = cdProfilAffectation;
}
public List<FoaParamEmploye> getFoaParamEmployes() {
return foaParamEmployes;
}
public void setFoaParamEmployes(List<FoaParamEmploye> pFoaParamEmployes) {
this.foaParamEmployes = pFoaParamEmployes;
}
}
Table FOA_PARAM_EMPLOYE_POSITION has this columns :
COD_ENTREP
ID_EMPLOYE
ID_POSITION
XQCIF
ACTEUR_MAJ_OCCUR
DATE_HEURE_MAJ_OCCUR
I got this exception :
A Foreign key refering com.groupama.middlgan.entities.FoaParamPosition from
com.groupama.middlgan.entities.FoaParamEmploye has the wrong number of column.
should be 2
If I add COD_ENTREP on inverseJoinColumns in my FoaParamEmploye entity, I got this exception :
Repeated column in mapping for collection:
com.groupama.middlgan.entities.FoaParamEmploye.foaParamPositions column: COD_ENTREP
Any idee ?
[I am assuming you are listing the columns for the association table FOA_PARAM_EMPLOYE_POSITION, not FOA_PARAM_EMPLOYE, as you state in your question.]
Your mappings imply FOA_PARAM_EMPLOYE_POSITION.COD_ENTREP is part of two foreign keys, one referencing FOA_PARAM_EMPLOYE and one referencing FOA_PARAM_POSITION. In practice these two foreign keys might contain the same value for COD_ENTREP, but this cannot be enforced by the database or JPA.
You should probably model the relationship differently, possibly add another, container-like, object that has bi-directional one-to-many relationships with both FoaParamEmploye and FoaParamPosition and shares parts of its primary key with the other two primary keys.
If you want to keep your inverseJoinColumn mapping you can do as follows,
#ManyToMany
#JoinTable(
name = "FOA_PARAM_EMPLOYE_POSITION",
joinColumns = { #JoinColumn(name = "ID_EMPLOYE"),
#JoinColumn(name = "COD_ENTREP") }
,
inverseJoinColumns = {#JoinColumn(name = "FOAPARAMPOSITION_COD_ENTREP"), #JoinColumn(name = "FOAPARAMPOSITION_ID_POSITION")}
)
private List<FoaParamPosition> foaParamPosition;
and
#ManyToMany
#JoinTable(
name = "FOA_PARAM_EMPLOYE_POSITION",
joinColumns = { #JoinColumn(name = "ID_POSITION"),
#JoinColumn(name = "COD_ENTREP") }
,
inverseJoinColumns = {#JoinColumn(name = "FOAPARAMEMPLOYE_COD_ENTREP"), #JoinColumn(name = "FOAPARAMEMPLOYE_ID_EMPLOYE")}
)
private List<FoaParamEmploye> foaParamEmploye;
the mappings are aligned with the code you've posted in your other question JPA Many To Many Select