[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] Binding both foreign object reference and foreign id field to object
|
Would someone mind instructing me on how I might go about binding both a foreign object reference and a foreign key to an object using EclipseLink's JPA implementation?
For example, I have the following simple domain objects (most methods and attributes left out to simplify example):
@Entity
@Table(name = "CUSTOMERS")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "NAME")
private String name;
// getters and setters below
}
@Entity
@Table(name = "JOBS")
Public class Job {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "DESCRIPTION")
private String description;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CUSTOMER_ID")
private Customer customer;
// ? JPA attribute, should I use @COLUMN?
private long customerId;
// getters and setters below
}
I would like to be able to fetch a Job domain object without loading the referenced Customer object (this the lazy load strategy). However, I would like to have access to the customerId associated in the link (even if it is read-only). Would I simply add another attribute and map it to the foreign key field storing the customerId? What happens if both this field and the reference is changed independently and the Job object is persisted (I realize I should write defensive code to prevent this, but what is the best pattern)?
Thanks for the help!
Regards,
Cody McCain
Director of Software Development
Frac Tech Services, Ltd.
(817) 349-4330 (office)
(580) 504-0797 (mobile)
Ops Support: opssupport@xxxxxxxxxxxx, (817) 764-0432
CONFIDENTIALITY NOTICE: This email message and any attachments hereto are intended only for use by the addressee(s) named herein and may contain information which is legally privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, or an authorized representative of the intended recipient, of this email message, you are hereby notified that any review, dissemination, distribution, copying, or use (including any reliance thereon) of this email message, and/or any attachment hereto, is strictly prohibited.
Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is free from virus or other defect and no responsibility is accepted by the sending company, its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use.
If you have received this email message in error, please immediately notify the sender by return email and permanently delete from your system, the original and any copies of this email and any attachments hereto and any printout hereof. Unauthorized interception of this email is a violation of federal criminal law.