Hi everyone,
I've a unique test case for which I could not find any solution any where in the net.
So, I've posted here seeking experts advice or guidance to resolve this issue.
I've many to many relation between Process and Errors table with associated table as ProcessError.
Entity Table: ProcessMaster
———————--------------
id (pk)
processId (unique)
Entity Table: Errors
——————-------
id (pk)
Code (unique)
Join Table: tblaeErrors
———————-------—
ScreenID(FK) — ProcessID field of ProcessMaster table
ErrorCode(FK) — Code field of Errors table
Response – varchar
composite_primary_key (ScreenID, Code)
I’ve problem in mapping the referenceColumn attribute in @JoinColumn element in ProcessError.java page.
ProcessMaster.java
--------------------
Code:
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true, dynamicUpdate=true)
@Table(name="[TBL:DT:MST:Process]",uniqueConstraints = {@UniqueConstraint(columnNames={"[ProcessID]"})})
public class ProcessMaster implements Serializable, SearchedRecord{
@Id
@Column(name = "id", unique = true, nullable = false)
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column(name = "[ProcessID]", nullable = false)
private String processID;
.......
@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.processMaster")
private List<ProcessError> processErrorList = new ArrayList<ProcessError>(0);
//getter & setter methods..
}
ProcessError .java
-----------------
Code:
@Entity
@Table(name=”[tblaeErrors]“)
@AssociationOverrides({
@AssociationOverride(name = “pk.errors”, joinColumns = @JoinColumn(name = “[ErrorCode]“, referencedColumnName=”[Code]")),
@AssociationOverride(name = "pk.process", joinColumns = @JoinColumn(name = "[ScreenID]", referencedColumnName="[ProcessID]"))
})
public class ProcessError implements Serializable, SearchedRecord{
@EmbeddedId
private ProcessErrorPK pk = new ProcessErrorPK();
@Column (name = "[Response]", nullable = true)
private String response;
......
}
[/code]
ProcessErrorPK.java
------------------
[code]
@Embeddable
public class ProcessErrorPK implements Serializable
{
@ManyToOne
private ProcessMaster processMaster;
@ManyToOne
private Errors errors;
............
}
[/code]
Errors.java
----------
[code]
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true, dynamicUpdate=true)
@Table(name="[TBLErrors]", uniqueConstraints = {@UniqueConstraint(columnNames={"[Code]"})})
public class Errors implements Serializable, SearchedRecord{
@Id
@Column(name = "id", unique = true, nullable = false)
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.errors")
private List<ProcessError> processList = new ArrayList<ProcessError>();
................
}
When I compile the code, I'm getting the following error. And I'm not sure, whether my mapping is right or wrong. So, please throw some light on this issue.
Caused by: org.hibernate.MappingException: property not found: _com_mhs_docutraxx_common_dao_ProcessError_pk.errorsin entity: com.mhs.docutraxx.common.dao.Errors
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:368)
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:334)
... 50 more
Caused by: org.hibernate.MappingException: property not found: _com_mhs_docutraxx_common_dao_ProcessError_pk on entity com.mhs.docutraxx.common.dao.Errors
at org.hibernate.mapping.PersistentClass.getProperty(PersistentClass.java:384)
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:358)
... 51 more
Please guide me how to point to unique columns(ProcessID, Code) of parent tables instead of primary key (id) from the join table (
ProcessError).
Thanks in advance
--Velu