[JIRA] (HHH-13883) Repeated Mapping exception on @JoinTable with overlapping foreign key colum
by Dominic Gibson (JIRA)
Dominic Gibson ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e57c91... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzYxMWI4Yzlj... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13883?atlOrigin=eyJpIjoiNzYxMW... ) HHH-13883 ( https://hibernate.atlassian.net/browse/HHH-13883?atlOrigin=eyJpIjoiNzYxMW... ) Repeated Mapping exception on @JoinTable with overlapping foreign key colum ( https://hibernate.atlassian.net/browse/HHH-13883?atlOrigin=eyJpIjoiNzYxMW... )
Issue Type: Bug Affects Versions: 5.4.12 Assignee: Unassigned Components: hibernate-core Created: 28/Feb/2020 02:20 AM Environment: spring boot 2.2.5, hibernate-core 5.4.12, h2 1.4.200, postgresql 9.2 Priority: Major Reporter: Dominic Gibson ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e57c91... )
Using this table structure (which is unfortunately fixed):
CREATE SEQUENCE folder_id_seq START WITH 1;
CREATE TABLE folder (
id BIGINT NOT NULL DEFAULT nextval( 'folder_id_seq' ),
tenantId VARCHAR (256) NOT NULL ,
PRIMARY KEY (id, tenantId)
);
CREATE TABLE folderTree (
tenantId varchar ,
folderId bigint ,
parentId bigint ,
PRIMARY KEY (tenantId, folderId, parentId),
FOREIGN KEY (tenantId, folderId) REFERENCES folder (tenantId, id),
FOREIGN KEY (tenantId, parentId) REFERENCES folder (tenantId, id)
);
And the following entity mappings:
FolderId.java
public class FolderId implements Serializable {
@Column
private String tenantId;
@Column
private Long id;
//equals, hashcode etc.
}
Folder.java
@Entity
@Table(name = "folder" )
@IdClass(FolderId.class)
public class Folder {
@Id
@Column(name = "tenantId" , updatable = false , nullable = false )
private String tenantId;
@Id
@SequenceGenerator(name = "folder_id_seq" , sequenceName = "folder_id_seq" , allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "folder_id_seq" )
@Column(name = "id" , updatable = false , nullable = false )
private Long id;
@OneToMany(mappedBy = "parent" , cascade = CascadeType.ALL, orphanRemoval = true )
private Set<Folder> children;
@ManyToOne
@JoinTable(name = "folderTree" ,
joinColumns = {
@JoinColumn(name = "tenantId" , referencedColumnName = "tenantId" ),
@JoinColumn(name = "parentId" , referencedColumnName = "id" )
},
inverseJoinColumns = {
@JoinColumn(name = "tenantId" , referencedColumnName = "tenantId" ),
@JoinColumn(name = "folderId" , referencedColumnName = "id" )
}
)
private Folder parent;
//equals, hashcode etc.
}
I'm getting a Repeated column mapping exception on the tenantId column. This happens regardless of whether I mark the @JoinColumns as updateable=false and insertable=false.
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.example.demo.Folder column: tenantId (should be mapped with insert= " false " update= " false " )
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:862)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:880)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:908)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:634)
at org.hibernate.mapping.RootClass.validate(RootClass.java:267)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:351)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:464)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1237)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391)
... 83 more
If I change the join table to duplicate the tenantId column as parentTenant, childTenant then hibernate will map everything correctly.
Am I doing something here?
( https://hibernate.atlassian.net/browse/HHH-13883#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13883#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100121- sha1:090dddf )
4 years, 9 months