我想使用 MyCollection 实现 java 提供的集合接口。它对于 EAGER 加载工作正常,但对于延迟加载,eclipselink 使用它自己的implemntation(IndirectList)。是否可以使用 MyCollection 进行延迟加载?
MyCollection 代码在这里:
package com.alta.convertor;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
public class MyCollection<E> implements Collection<E>,Cloneable{
Collection<E> collection;
@SuppressWarnings({ "unchecked", "rawtypes" })
public MyCollection() {
this(new Vector());
}
public MyCollection(Collection<E> collection) {
this.collection=collection;
}
@Override
public int size() {
return collection.size();
}
@Override
public boolean isEmpty() {
return collection.isEmpty();
}
@Override
public boolean contains(Object o) {
return collection.contains(o);
}
@Override
public Iterator<E> iterator() {
return collection.iterator();
}
@Override
public Object[] toArray() {
return collection.toArray();
}
@Override
public <T> T[] toArray(T[] a) {
return collection.toArray(a);
}
@Override
public boolean add(E e) {
return false;
}
@Override
public boolean remove(Object o) {
return collection.remove(o);
}
@Override
public boolean containsAll(Collection<?> c) {
return collection.containsAll(c);
}
@Override
public boolean addAll(Collection<? extends E> c) {
return collection.addAll(c);
}
@Override
public boolean removeAll(Collection<?> c) {
return collection.removeAll(c);
}
@Override
public boolean retainAll(Collection<?> c) {
return collection.retainAll(c);
}
@Override
public void clear() {
collection.clear();
}
}
我的实体类为:
@Entity
public class Person implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="personid")
private Long personId;
private String firstName;
private String lastName;
private String email;
@OneToMany(cascade = CascadeType.ALL,mappedBy="person",targetEntity=Address.class,fetch=FetchType.EAGER)
私人 MyCollection 地址数组;
public Person() {
}
public Person(String firstName, String lastName, String email) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public MyCollection<Address> getAddressArray() {
return addressArray;
}
public void setAddressArray(MyCollection<Address> address) {
this.addressArray = address;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Long getPersonId() {
return personId;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
}