I'm relativly new to the world of EclipseLink, I've been reading through the documentation, however I'm having a real problem trying to represent the following table.
PTY_NO | REF_OBG
6544 45663
6544 1234
6544 97543
6544 1123
6544 77897
Ideally I'd like to represent the above data as follows.
@Entity
@Table(name="FCS_ISSR_OBG")
public class fcs_issr_obg implements Serializable {
@Id
@Column(name="PTY_NO")
private long pty_no;
@Column(name="REF_OBG")
private List<long> ref_obg;
...
As once I have the data in this form I plan to serialize the class into a Coherence cache.
However the annotation I've used doesn't actually compile ...
Any help would be gratefully received.
.. update
The best I've managed to come up with so far is
@Entity
@Table(name="FCS_ISSR_OBG")
public class fcs_issr_obg implements Serializable, PortableObject {
private static final long serialVersionUID = 1L;
@Id
@Column(name="PTY_NO")
private long pty_no;
@ElementCollection(targetClass = Long.class, fetch = EAGER)
@CollectionTable(
name = "FCS_ISSR_OBG",
joinColumns=@JoinColumn(name="PTY_NO")
)
@Column(name ="REF_OBG")
private List<Long> collection;
However this results in 2 queries ... which is not really what I'm after.
Cheers Rich
To force any relationship to be fetched with the parent query the @JoinFetch annotation can be used in EclipseLink.
Although, reading the collection in a separate query may be the best solution depending on the data.
You can also use @BatchFetch in EclipseLink to batch fetch a relationship (still 2 queries, but not n+1 queries). I did a comparison on batch and join fetching in my blog recently, see,
http://java-persistence-performance.blogspot.com/
I've not been able to test this, but perhaps introducing an embeddable object may reduce the query count. Something like this:
with the embeddable looking like this
You only get the collection when you specifically ask for it. Sorry for the weak answer but I'm limited to what I can test here.