Brian Forkan (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzg2NjAwYTE1...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16340?atlOrigin=eyJpIjoiNzg2Nj...
) HHH-16340 (
https://hibernate.atlassian.net/browse/HHH-16340?atlOrigin=eyJpIjoiNzg2Nj...
) Duplicate column exception when using an EmbeddedId in a structure with Inheritance -
Hibernate V6 (
https://hibernate.atlassian.net/browse/HHH-16340?atlOrigin=eyJpIjoiNzg2Nj...
)
Issue Type: Bug Affects Versions: 6.0.0 Assignee: Unassigned Components:
hibernate-orm-modules Created: 21/Mar/2023 04:18 AM Environment: Java 17
Hibernate ORM >6.0 Priority: Major Reporter: Brian Forkan (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Caused by: org.hibernate.MappingException: Column 'TYPE' is duplicated in mapping
for entity 'org.hibernate.bugs.JPAUnitTestCase$Node' (use
'@Column(insertable=false, updatable=false)' when mapping multiple properties to
the same column)
The exception above happens in Hibernate 6.0 and above.
https://github.com/brianforkan/hibernate-test-case-templates/commit/ea51a...
(
https://github.com/brianforkan/hibernate-test-case-templates/commit/ea51a...
)
I have created two test cases, one for Hibernate 5, which works fine and one for Hibernate
6 which fails.
This is the structure I am using:
@Entity(name = "Node")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE")
@DiscriminatorOptions(insert = false)
public static class Node {
@EmbeddedId
private NodeId id;
@Column(name = "NAME")
private String name;
public Node(NodeId id, String name) {
this.id = id;
this.name = name;
}
public NodeId getId() {
return id;
}
public void setId(NodeId id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
protected Node() {
}
}
@Entity
@DiscriminatorValue("NODEA")
public static class NodeA extends Node {
protected NodeA() {
}
public NodeA(NodeId nodeId, String name) {
super(nodeId, name);
}
}
@Entity
@DiscriminatorValue("NODEB")
public static class NodeB extends Node {
protected NodeB() {
}
public NodeB(NodeId nodeId, String name) {
super(nodeId, name);
}
}
@Embeddable
public static class NodeId implements Serializable {
@Column(name = "ID")
private String id;
public String getId() {
return id;
}
public NodeId() {}
public NodeId(String id, String type) {
this.id = id;
this.type = type;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
NodeId nodeId = (NodeId) o;
if (!Objects.equals(id, nodeId.id)) {
return false;
}
return Objects.equals(type, nodeId.type);
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (type != null ? type.hashCode() : 0);
return result;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Column(name = "TYPE", insertable = false, updatable = false)
private String type;
}
(
https://hibernate.atlassian.net/browse/HHH-16340#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16340#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100218- sha1:518c67a )