-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: many to many join columns with composite primary keys
PostPosted: Mon Aug 09, 2010 12:22 am 
Newbie

Joined: Tue Oct 07, 2008 12:17 pm
Posts: 13
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


Top
 Profile  
 
 Post subject: Re: many to many join columns with composite primary keys
PostPosted: Wed Aug 11, 2010 1:49 pm 
Newbie

Joined: Tue Oct 07, 2008 12:17 pm
Posts: 13
Could anyone help on this?

--Velu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.