-->
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: Help mapping a field of composite key to entity
PostPosted: Tue Jan 28, 2014 4:49 pm 
Newbie

Joined: Thu Apr 08, 2010 11:34 am
Posts: 7
Hello,

I have two entities, a Job and JobExecution. A job can be executed multiple times.

Job (jobId, name) - a physical table with columns (job_id, name)
JobExecution ( Job, scheduledDate, status ) - a physical table with columns ( job_id, scheduled_date, status)


The primary key of the JobExecution table is (jobId, scheduledDate)

class JobExecution
{
@EmbeddedId
JobExecutionPk pk;

@Column(name = "status")
String status;
}

class JobExecutionPk
{
Job job;
Date scheduledDate;

public boolean equals() { ...}
public int hashCode() { ... }
}

class Job
{
@Id
UUID jobId;

@Column(name="name")
String name;
}

What annotations do I need to use to map the embedded Id to the Job table?
I assume I need a @ManyToOne but
Where should these annotations go? Should I annotate the field "pk" of JobExecution class or in the "job" field of the JobExecutionPk ?

Any pointers to a similar example would be helpful. I can't seem to find a similar mapping example.

Thank you

-Jorge


Top
 Profile  
 
 Post subject: Re: Help mapping a field of composite key to entity
PostPosted: Tue Jan 28, 2014 5:00 pm 
Newbie

Joined: Thu Apr 08, 2010 11:34 am
Posts: 7
should I define the JobInstancePK as:

class JobExecutionPk
{
UUID jobId;
Date scheduledDate;

public boolean equals() { ...}
public int hashCode() { ... }
}

But in that case...I have no clue on how to perform the mapping.


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.