Skip to content

Commit

Permalink
fixing issue with foreign key constraint and inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
openwms committed Dec 1, 2023
1 parent c7b31f7 commit c541a4d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyColumn;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
Expand All @@ -48,12 +46,10 @@
*/
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "WMS_REC_ORDER_POSITION",
uniqueConstraints = @UniqueConstraint(name = "UC_ORDER_ID_POS", columnNames = { "C_ORDER_ID", "C_POS_NO" }))
public abstract class AbstractReceivingOrderPosition extends BaseEntity implements Serializable {

@ManyToOne(optional = false, targetEntity = ReceivingOrder.class)
@JoinColumn(name = "C_ORDER_ID", referencedColumnName = "C_ORDER_ID", foreignKey = @ForeignKey(name = "FK_REC_POS_ORDER_ID"))
@JoinColumn(name = "C_ORDER_ID", referencedColumnName = "C_ORDER_ID")
private ReceivingOrder order;

/** The position number is a unique index within a single {@link ReceivingOrder} instance. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
import org.openwms.wms.receiving.inventory.Product;
import org.springframework.context.ApplicationEventPublisher;

import javax.persistence.AssociationOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
Expand All @@ -44,7 +48,12 @@
* @author Heiko Scherrer
*/
@Entity
@Table(name = "WMS_REC_ORDER_POS_PRODUCT")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
// Bug in hibernate prevents overrding fkcontraints
@AssociationOverride(name = "order", joinColumns =
@JoinColumn(name = "C_ORDER_ID", referencedColumnName = "C_ORDER_ID", foreignKey = @ForeignKey(name = "FK_REC_POS_ORDER_ID_PROD")))
@Table(name = "WMS_REC_ORDER_POS_PRODUCT",
uniqueConstraints = @UniqueConstraint(name = "UC_ORDER_ID_POS", columnNames = { "C_ORDER_ID", "C_POS_NO" }))
public class ReceivingOrderPosition extends AbstractReceivingOrderPosition implements Convertable, Serializable {

/** The quantity that is expected to be receipt. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
import org.ameba.system.ValidationUtil;
import org.openwms.wms.receiving.ValidationGroups;

import javax.persistence.AssociationOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
Expand All @@ -32,7 +38,13 @@
* @author Heiko Scherrer
*/
@Entity
@Table(name = "WMS_REC_ORDER_POS_TU")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
// Bug in hibernate prevents overrding fkcontraints
@AssociationOverride(name = "order", joinColumns =
@JoinColumn(name = "C_ORDER_ID", referencedColumnName = "C_ORDER_ID"),
foreignKey = @ForeignKey(name = "FK_REC_POS_ORDER_ID_TU"))
@Table(name = "WMS_REC_ORDER_POS_TU",
uniqueConstraints = @UniqueConstraint(name = "UC_ORDER_ID_POS_TU", columnNames = { "C_ORDER_ID", "C_POS_NO" }))
public class ReceivingTransportUnitOrderPosition extends AbstractReceivingOrderPosition implements Convertable, Serializable {

/** The business key of the expected {@code TransportUnit} that is expected to be received. */
Expand Down

0 comments on commit c541a4d

Please sign in to comment.