Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case 03436792 #252

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package org.hibernate.bugs;

import org.apache.commons.lang.StringUtils;

import javax.persistence.Column;
import javax.persistence.Embeddable;


@SuppressWarnings("serial")
@Embeddable
public class ClaimFolderPK {

@Column(updatable = false, name = "DB_PARTN_NBR")
protected String partitionNumber;


@Column(updatable = false, name = "PROD_TRNG_CD")
protected String productionOrTrainingCode;


@Column(updatable = false, name = "CLM_NBR")
protected String claimNumber;





public String getPartitionNumber() {
if (this.partitionNumber == null) {
this.partitionNumber = this.claimNumber.substring(8);
}
return partitionNumber;
}

public void setPartitionNumber(String partitionNumber) {
this.partitionNumber = partitionNumber;
}

public String getProductionOrTrainingCode() {
return productionOrTrainingCode;
}

public void setProductionOrTrainingCode(String productionOrTrainingCode) {
this.productionOrTrainingCode = productionOrTrainingCode;
}

public String getClaimNumber() {
return claimNumber;
}

public void setClaimNumber(String claimNumber) {
this.claimNumber = claimNumber;
if(StringUtils.isNotBlank(claimNumber) && claimNumber.length()>8){
this.partitionNumber=this.claimNumber.substring(8);
}
}

public int hashCode() {
if (partitionNumber == null) {
return (int) productionOrTrainingCode.hashCode()
+ (int) claimNumber.hashCode();
} else {
return (int) partitionNumber.hashCode()
+ (int) productionOrTrainingCode.hashCode()
+ (int) claimNumber.hashCode();
}
}

public boolean equals(Object obj) {
if (obj == null || !(obj instanceof ClaimFolderPK)) {
return false;
}
if (obj == this) {
return true;
}

ClaimFolderPK pk = (ClaimFolderPK) obj;
if (partitionNumber == null) {
return pk.productionOrTrainingCode
.equals(this.productionOrTrainingCode)
&& pk.claimNumber.equals(this.claimNumber);
} else {
return pk.partitionNumber.equals(this.partitionNumber)
&& pk.productionOrTrainingCode
.equals(this.productionOrTrainingCode)
&& pk.claimNumber.equals(this.claimNumber);
}

}

@Override
public String toString() {
return "ClaimReference [partitionNumber=" + partitionNumber
+ ", productionOrTrainingCode=" + productionOrTrainingCode
+ ", claimNumber=" + claimNumber + "]";
}

public static ClaimFolderPK getPK(String clmNbr, String prodTrngCd){
ClaimFolderPK pk=new ClaimFolderPK();
pk.setClaimNumber(clmNbr);
pk.setProductionOrTrainingCode(prodTrngCd);
return pk;

}

/*
* check the string lengths
*/
private static final int MAX_CLAIM_NBR_LENGTH = 10;
private static final int MAX_PARTITION_LENGTH = 2;
private static final int MAX_PT_LENGTH = 1;

public Remark verify() {
if (this.claimNumber.length() > MAX_CLAIM_NBR_LENGTH) {
return new Remark("length of idRef is greater than "
+ MAX_CLAIM_NBR_LENGTH);
}
if (this.partitionNumber.length() > MAX_PARTITION_LENGTH) {
return new Remark("length of partition is greater than "
+ MAX_PARTITION_LENGTH);
}
if (this.productionOrTrainingCode.length() > MAX_PT_LENGTH) {
return new Remark("length of productionOrTraining is greater than "
+ MAX_PT_LENGTH);
}

return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.hibernate.bugs;

import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.Valid;

@Entity
@Table(name="CLAIMANT")
public class ClaimantEntity {

@EmbeddedId
private ClaimantFolderPK id;

public ClaimantFolderPK getId() {
return id;
}

public void setId(ClaimantFolderPK id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Column(name = "NAME")
private String name;

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@LazyGroup("injuryEntities")
@LazyToOne(LazyToOneOption.PROXY)
@JoinColumns({
@JoinColumn(name = "CLM_NBR", referencedColumnName = "CLM_NBR"),
@JoinColumn(name = "DB_PARTN_NBR", referencedColumnName = "DB_PARTN_NBR"),
@JoinColumn(name = "PROD_TRNG_CD", referencedColumnName = "PROD_TRNG_CD"),
@JoinColumn(name = "CLM_SUB_NBR", referencedColumnName = "CLM_SUB_NBR") })
@Valid
private InjuryEntity injury;

public InjuryEntity getInjury() {
return injury;
}

public void setInjury(InjuryEntity injury) {
this.injury = injury;
}

public PartyEntity getClmtPtyRole() {
return clmtPtyRole;
}

public void setClmtPtyRole(PartyEntity clmtPtyRole) {
this.clmtPtyRole = clmtPtyRole;
}

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@LazyToOne(LazyToOneOption.PROXY)
@JoinColumn(name = "CLM_PTY_ROLE_ID", referencedColumnName = "CLM_PTY_ROLE_ID")
@Valid
@NotFound(action= NotFoundAction.IGNORE)
private PartyEntity clmtPtyRole;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.hibernate.bugs;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@Embeddable
public class ClaimantFolderPK {
// default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;

@Column(updatable = false, name = "CLM_SUB_NBR")
protected String clmSubNbr;


protected ClaimFolderPK claimFolderPK;

public ClaimFolderPK getClaimFolderPK() {
return claimFolderPK;
}

public void setClaimFolderPK(ClaimFolderPK claimFolderPK) {
this.claimFolderPK = claimFolderPK;
}

public ClaimantFolderPK() {
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((claimFolderPK == null) ? 0 : claimFolderPK.hashCode());
result = prime * result + ((clmSubNbr == null) ? 0 : clmSubNbr.hashCode());
return result;
}

@Override
public String toString() {
return "ClaimantFolderPK [clmSubNbr=" + clmSubNbr + ", claimFolderPK=" + claimFolderPK + "]";
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ClaimantFolderPK other = (ClaimantFolderPK) obj;
if (claimFolderPK == null) {
if (other.claimFolderPK != null)
return false;
} else if (!claimFolderPK.equals(other.claimFolderPK))
return false;
if (clmSubNbr == null) {
if (other.clmSubNbr != null)
return false;
} else if (!clmSubNbr.equals(other.clmSubNbr))
return false;
return true;
}

public String getClmSubNbr() {
return this.clmSubNbr;
}

public void setClmSubNbr(String clmSubNbr) {
this.clmSubNbr = clmSubNbr;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.hibernate.bugs;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="CLAIMANT")
public class InjuryEntity {

@EmbeddedId
private ClaimantFolderPK id;

public ClaimantFolderPK getId() {
return id;
}

public void setId(ClaimantFolderPK id) {
this.id = id;
}

public String getInjuryName() {
return injuryName;
}

public void setInjuryName(String injuryName) {
this.injuryName = injuryName;
}

@Column(name = "INJ_NAME")
private String injuryName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,28 @@ public void destroy() {
public void hhh123Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
// Do stuff...
// Do stuff..laimantEntity clmt = new Claim

//Parent Entity persist
ClaimantEntity clmt = new ClaimantEntity();
ClaimantFolderPK pk = new ClaimantFolderPK();
ClaimFolderPK clmPk = new ClaimFolderPK();
clmPk.setClaimNumber("1111");
clmPk.setPartitionNumber("11");
clmPk.setProductionOrTrainingCode("T");
pk.setClmSubNbr("123");
pk.setClaimFolderPK(clmPk);
clmt.setId(pk);
entityManager.perist(clmt);

//association of parent entity of same table
//claimant to Injury OneToOne relation
InjuryEntity inj = new InjuryEntity ();
inj.setId(pk);
inj.setInjuryName("injname");
clmt.setInjury(inj);
entityManager.merge(clmt); // issue is here while merging, it's fetchinh claimantEntity joining with injury and party entity..so on if any associations

entityManager.getTransaction().commit();
entityManager.close();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.hibernate.bugs;

import org.hibernate.annotations.LazyGroup;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

@Entity
@Table(name="PARTY")
public class PartyEntity {

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "CLM_PTY_ROLE_ID")
private int clmPtyRoleId;

@Column(name="IS_ACTIVE")
private String isActive;

public int getClmPtyRoleId() {
return clmPtyRoleId;
}

public void setClmPtyRoleId(int clmPtyRoleId) {
this.clmPtyRoleId = clmPtyRoleId;
}

public String getIsActive() {
return isActive;
}

public void setIsActive(String isActive) {
this.isActive = isActive;
}

@OneToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL, mappedBy = "clmtPtyRole",optional = false)
@LazyGroup("claimantPartyEntities")
@LazyToOne(LazyToOneOption.NO_PROXY)
private ClaimantEntity claimant;
}