Andreas Kessler (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjljODAwZjhi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16032?atlOrigin=eyJpIjoiNjljOD...
) HHH-16032 (
https://hibernate.atlassian.net/browse/HHH-16032?atlOrigin=eyJpIjoiNjljOD...
) Auditing @OneToMany parent child relation with composite key and owner on single side
not working (
https://hibernate.atlassian.net/browse/HHH-16032?atlOrigin=eyJpIjoiNjljOD...
)
Change By: Andreas Kessler (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
I have a parent child {{@OneToMany}} relation with the one side as owner. The relation is
bidirectional.
The reference table {{ParentChild}} has a composite key ({{parentId}}, {{childId}}) and
has an additional attribute {{name}}. All changes should be audited by envers, therefore
we have chosen the owner side on the parent side that adding and removing a child creates
a revision of the parent.
But generating the DDL throws the following exception:
{noformat}rg.hibernate.MappingException: Repeated column in mapping for entity:
com.comfone.audit.test.audittest.data.ParentChild_AUD column: parent_id (should be mapped
with insert="false" update="false"){noformat}
Envers tries to generate the {{ParentChild_AUD }}table containing the composite key and
the audited fields but it also tries to add two columns {{parent_id }}and {{child_id
}}which conflicts with the composite key.
Is this a bug or do I something wrong?
Thanks for your help!
Cheers Andy
Generated DDL:
{code:xml}<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping auto-import="false">
<class entity-name="com.comfone.audit.test.audittest.data.ParentChild_AUD"
discriminator-value="ParentChild" table="parent_child_AUD"
abstract="false">
<composite-id name="originalId">
<key-property name="childId" type="long">
<column name="child_id" length="255" scale="2"
precision="19"/>
</key-property>
<key-property name="parentId" type="long">
<column name="parent_id" length="255" scale="2"
precision="19"/>
</key-property>
<key-many-to-one type="integer"
class="org.hibernate.envers.DefaultRevisionEntity" name="REV">
<column name="REV"/>
</key-many-to-one>
</composite-id>
<property insert="true" update="false" name="REVTYPE"
type="org.hibernate.envers.internal.entities.RevisionTypeType"/>
<property insert="true" update="false" name="name"
type="string">
<column name="name" length="255" scale="2"
precision="19"/>
</property>
<property insert="false" update="false" name="child_id"
type="long">
<column name="child_id" length="255" scale="2"
precision="19"/>
</property>
<property insert="true" update="false" name="parent_id"
type="long">
<column name="parent_id" length="255" scale="2"
precision="19"/>
</property>
</class>
</hibernate-mapping>{code}
Parent.java:
{code:java}@Entity
@Audited
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode(of = {"id"})
public class Parent implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@AuditMappedBy(mappedBy = "parent")
@Builder.Default
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "PARENT_ID", insertable = false, updatable = false)
private Set<ParentChild> parentChildren = new HashSet<>();
@Version
@Setter(AccessLevel.NONE)
private Long version;
public void addParentChild(ParentChild parentChild) {
parentChild.setParent(this);
this.parentChildren.add(parentChild);
}
public void removeParentChild(ParentChild parentChild) {
parentChild.setParent(null);
this.parentChildren.remove(parentChild);
}
}{code}
ParentChild.java:
{code:java}@Entity
@Audited
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode(of = {"parentChildId"})
public class ParentChild implements Serializable {
@EmbeddedId
private final ParentChildId parentChildId = new ParentChildId();
private String name;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@MapsId("parentId")
@JoinColumn(insertable = false, updatable = false)
private Parent parent;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@MapsId("childId")
@JoinColumn(insertable = false, updatable = false)
private Child child;
@Version
@Setter(AccessLevel.NONE)
private Long version;
}{code}
Child.java:
{code:java}@Entity
@Audited
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode(of = {"id"})
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
}{code}
Test project:
[
https://github.com/hotkeeper/jpa-envers-test|https://github.com/hotkeeper...]
(
https://hibernate.atlassian.net/browse/HHH-16032#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16032#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#100214- sha1:b03f6a4 )