Although kind of similar to HHH-7625 I encountered another problem with {{@Entity}} using {{@EmbeddedId}}. Consider the following minimal example:
h2. Parent.java
{code:java} import java.io.Serializable; import java.util.List; import java.util.Objects; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; import org.hibernate.envers.Audited;
@Entity @Audited public class Parent implements Serializable {
@Id private String id;
@OneToMany(mappedBy = "id.parent") private List<Child> children;
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public List<Child> getChildren() { return children; }
public void setChildren(List<Child> children) { this.children = children; }
@Override public int hashCode() { int hash = 5; hash = 97 * hash + Objects.hashCode(this.id);
return hash; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; }
if (obj == null) { return false; }
if (getClass() != obj.getClass()) { return false; }
final Parent other = (Parent) obj;
return Objects.equals(this.id, other.id); } } {code}
h2. Child.java
{code:java} import java.io.Serializable; import java.util.Objects; import javax.persistence.EmbeddedId; import javax.persistence.Entity;
@Entity public class Child implements Serializable {
@EmbeddedId private ChildId id;
public ChildId getId() { return id; }
public void setId(ChildId id) { this.id = id; }
@Override public int hashCode() { int hash = 7; hash = 67 * hash + Objects.hashCode(this.id);
return hash; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; }
if (obj == null) { return false; }
if (getClass() != obj.getClass()) { return false; }
final Child other = (Child) obj;
return Objects.equals(this.id, other.id); } } {code}
h2. ChildId.java
{code:java} import java.io.Serializable; import java.util.Objects; import javax.persistence.Embeddable; import javax.persistence.JoinColumn; import javax.persistence.JoinColumns; import javax.persistence.ManyToOne;
@Embeddable public class ChildId implements Serializable {
@ManyToOne @JoinColumns({ @JoinColumn(name = "parent_id", referencedColumnName = "id") }) private Parent parent;
private Integer number;
public Parent getParent() { return parent; }
public void setParent(Parent parent) { this.parent = parent; }
public Integer getNumber() { return number; }
public void setNumber(Integer number) { this.number = number; }
@Override public int hashCode() { int hash = 5; hash = 79 * hash + Objects.hashCode(this.parent); hash = 79 * hash + Objects.hashCode(this.number);
return hash; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; }
if (obj == null) { return false; }
if (getClass() != obj.getClass()) { return false; }
final ChildId other = (ChildId) obj;
if (!Objects.equals(this.parent, other.parent)) { return false; }
return Objects.equals(this.number, other.number); } } {code}
which leads to
{quote} {{ Caused by: org.hibernate.MappingException: Unable to read the mapped by attribute for children in Child! at org.hibernate.envers.configuration.internal.metadata.CollectionMetadataGenerator.getMappedBy(CollectionMetadataGenerator.java:868) }} {quote} |
|