[JIRA] (HHH-16908) Fail to compute column mapping on entity with idClass having one field as pk of a OneToOne association
by Erwan Moutymbo (JIRA)
Erwan Moutymbo ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=640210c... ) *commented* on HHH-16908 ( https://hibernate.atlassian.net/browse/HHH-16908?atlOrigin=eyJpIjoiNjI3NW... )
Re: Fail to compute column mapping on entity with idClass having one field as pk of a OneToOne association ( https://hibernate.atlassian.net/browse/HHH-16908?atlOrigin=eyJpIjoiNjI3NW... )
I have tried to reversed the OneToOne association to declare it on the SpecialProduct :
@Getter
@Entity
@EqualsAndHashCode(onlyExplicitlyIncluded = true )
@ToString(onlyExplicitlyIncluded = true )
@Table(name = "SPECIAL_OPERATOR_PRICES_POINTS" )
@IdClass(SpecialPricePoint.SpecialPricePointPK.class)
@NoArgsConstructor(access = PROTECTED)
public class SpecialPricePoint {
public SpecialPricePoint(SpecialOperator operator ,
String wholesalePrice) {
this. operator = operator ;
this.wholesalePrice = wholesalePrice;
}
@ManyToOne
@ToString.Include
@Setter(PACKAGE)
@EqualsAndHashCode.Include
@JoinColumn(name = "PROVIDER_ID" , referencedColumnName = "PROVIDER_ID" )
@JoinColumn(name = "OPERATOR_ID" , referencedColumnName = "OPERATOR_ID" )
@MapsId
private SpecialOperator operator ;
@Id
@Column(name = "PRICE_POINT" , nullable = false )
@ToString.Include
@EqualsAndHashCode.Include
String wholesalePrice;
@OneToOne(mappedBy = "wholesalePrice" , cascade = { PERSIST, MERGE, REMOVE }, orphanRemoval = true )
@Cache(usage = READ_WRITE)
private SpecialProduct product;
public void setProduct(SpecialProduct product) {
product.setWholesalePrice( this );
this.product = product;
}
@Value
@Embeddable
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor
public static class SpecialPricePointPK implements Serializable {
@Embedded
@NonFinal
@AttributeOverride(name = "provider" , column = @Column(name = "PROVIDER_ID" , nullable = false ))
@AttributeOverride(name = "operatorId" , column = @Column(name = "OPERATOR_ID" , nullable = false ))
SpecialOperatorPK operator ;
@NonFinal
String wholesalePrice;
}
}
@Getter
@EqualsAndHashCode(onlyExplicitlyIncluded = true )
@ToString(onlyExplicitlyIncluded = true )
@NoArgsConstructor(access = PROTECTED)
@Table(name = "SPECIAL_PRODUCTS" )
@Entity
@IdClass(SpecialProduct.SpecialProductPK.class)
@Cacheable
@Cache(usage = READ_WRITE)
@OptimisticLocking(type = OptimisticLockType.DIRTY)
@DynamicUpdate
public class SpecialProduct {
public SpecialProduct( String productId,
SpecialPricePoint wholesalePrice) {
this.productId = productId;
this.wholesalePrice = wholesalePrice;
}
@Id
@EqualsAndHashCode.Include
@ToString.Include
@Column(name = "PRODUCT_ID" , nullable = false )
private String productId;
@Setter
@ToString.Include
@EqualsAndHashCode.Include
@OneToOne(optional = false )
@JoinColumn(name = "WHOLESALE_PRICE_AMOUNT" ,
referencedColumnName = "PRICE_POINT" ,
updatable = false ,
insertable = false )
@JoinColumn(name = "OPERATOR_ID" , referencedColumnName = "OPERATOR_ID" , updatable = false , insertable = false )
@JoinColumn(name = "PROVIDER_ID" , referencedColumnName = "PROVIDER_ID" , updatable = false , insertable = false )
@MapsId
private SpecialPricePoint wholesalePrice;
@CreationTimestamp
@Column(name = "CREATION_DATE" , nullable = false , updatable = false )
private Instant creationDate;
@OptimisticLock(excluded = true )
@UpdateTimestamp
@Column(name = "MODIFICATION_DATE" , nullable = false )
private Instant modificationDate;
@Value
@Embeddable
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor
public static class SpecialProductPK implements Serializable {
@Embedded
@NonFinal
@AttributeOverride(name = " operator.provider" , column = @Column(name = "PROVIDER_ID" , nullable = false ))
@AttributeOverride(name = " operator.operatorId" , column = @Column(name = "OPERATOR_ID" , nullable = false ))
@AttributeOverride(name = "wholesalePrice" , column = @Column(name = "WHOLESALE_PRICE_AMOUNT" , nullable = false ))
SpecialPricePointPK wholesalePrice;
@NonFinal
String productId;
}
}
This time the mapping work and I can persist a SpecialProduct but due to https://hibernate.atlassian.net/browse/HHH-16810 I cannot delete it neither the SpecialPricePoint once a SpecialProduct has been added.
Sources can be found in branch reversdOneToOne on https://github.com/emouty/hibernate-issues/tree/reversedOneToOne
( https://hibernate.atlassian.net/browse/HHH-16908#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16908#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#100230- sha1:acc9c6f )
2 years, 9 months