Raised: org.hibernate.MappingException: repeat column when matching for an object

I am new to working with JPA with maven and JBOSS, with Restful, in order to make my application, I had the following problem while running DEPLOY

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: com.company.test_resources_war_1.0-SNAPSHOTPU] Unable to build EntityManagerFactory Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: database.Photo column: fid_module (should be mapped with insert = \ "false \" update = \ "false \") "}} 

Wrong step, check all postls solutions, but didn’t find anything, can someone help me ??

Thanks in advance

Below I show the SQL code in postgres that I have, and I did the mapping.

I have three tables ( activity , event and photo ), where one of them ( photo ) refers to the other two ( activity and event ), but in one column ( photo.fid_module )

SQL Code (enginer database -> Postgresql):

 CREATE TABLE activity ( id_activity integer not null, name character varying(150), description text, CONSTRAINT id_activity_pk PRIMARY KEY (id_activity) ) CREATE TABLE event ( id_event integer not null, name character varying(150), description text, date timestamp without time zone, CONSTRAINT id_event_pk PRIMARY KEY (id_event) ) CREATE TABLE photo( id_photo integer not null, path character varying(150), fid_module integer not null, CONSTRAINT id_photo_pk PRIMARY KEY (id_photo), CONSTRAINT fk_photo_activity FOREIGN KEY (fid_module) REFERENCE activity (id_activity) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT fk_photo_event FOREIGN KEY (fid_module) REFERENCE event (id_event) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) 

Now I did the mapping using Netbenas and gave me the following code (I did the mapping for the three tables, but in my view the problem is in the Photo.java class).

 @Entity @Table(name = "photo") @XmlRootElement @NamedQueries({ @NamedQuery(name = "photo.findAll", query = "SELECT p FROM Photo p"), @NamedQuery(name = "photo.findByFidPhoto", query = "SELECT p FROM Photo p WHERE p.fidphoto = :fidphoto"), @NamedQuery(name = "photo.findByIdPhoto", query = "SELECT p FROM Photo p WHERE p.idphoto = :idphoto")}) public class Photo implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id_photo") private Integer idPhoto; @Column(name = "path") private Recurso fidPath; @JoinColumn(name = "fid_module", referencedColumnName = "id_activity") @ManyToOne(optional = false, fetch = FetchType.LAZY) private SliderWebHome fidModule; @JoinColumn(name = "fid_module", referencedColumnName = "id_event") @ManyToOne(optional = false, fetch = FetchType.LAZY) private Publicacion fidModule1; public ModuloRecurso() { } ....... } 

I use JPA for persistence (but mvn clean install and mvn jboss-as: deploy somewhat put me out of sleeping dependencies), can someone tell me what my error is, or can solve this problem. Thanks.

+14
java maven postgresql hibernate jpa
source share
2 answers

As noted in another answer, your Java code indicates the same join column name for two fields that cannot work.

If this Java code is generated by the netbeans mapping tool, as you can see from your note

Now the mapping I did using Netbenas and gave me the following code ...

poor Java mapping is probably caused by a poor combination of constraints in your SQL.

The definition for the photo table indicates the following:

  CONSTRAINT fk_photo_activity FOREIGN KEY (fid_module) REFERENCE activity (id_activity) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT fk_photo_event FOREIGN KEY (fid_module) REFERENCE event (id_event) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION 

which is trying to make the fid_module column a foreign key referring to activity , as well as a foreign key referring to event , which cannot work.

If you need foreign keys for photo for both of these tables, you need to use two different columns.

+9
source share

You have two columns with the same name.

  @JoinColumn(name = "fid_module", referencedColumnName = "id_activity") @JoinColumn(name = "fid_module", referencedColumnName = "id_event") 

Change one of the name attributes!

In your exception, you can read:

 Repeated column in mapping for entity 
+12
source share

All Articles