{noformat}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){noformat}
The exception above happens in Hibernate 6.0 and above.
[https://github.com/brianforkan/hibernate-test-case-templates/commit/ea51a1f55b248edacebd6e5aab5e8a071a8ad296|https://github.com/brianforkan/hibernate-test-case-templates/commit/ea51a1f55b248edacebd6e5aab5e8a071a8ad296|smart-link]
I have created two test cases, one for Hibernate 5, which works fine and one for Hibernate 6 which fails.
Following the suggestion in the exception does not fix the problem.
This is the structure I am using:
{noformat} @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; }{noformat} |
|