我正在使用Dozer将我的实体映射到我的DTO
我的问题是在一个懒惰加载集合的实体上。我使用映射告诉Dozer排除集合字段以避免延迟加载异常
即使有这个特定的映射,Dozer似乎试图映射集合,然后Hibernate抛出Lazy Loading异常......
这是我的具体映射:
<mapping map-id="employe_simple">
<class-a>ch.tupperware.tuppergestion.entity.AbstractEmployeEntity</class-a>
<class-b>ch.tupperware.tuppergestion.dto.AbstractEmployeDto</class-b>
<field-exclude>
<a>listeClients</a>
<b>listeClients</b>
</field-exclude>
<field-exclude>
<a>reunions</a>
<b>reunions</b>
</field-exclude>
<field-exclude>
<a>responsable</a>
<b>responsable</b>
</field-exclude>
</mapping>
这是我的实体:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@org.hibernate.annotations.DiscriminatorFormula(value="TYPE_PERSONNE")
@Table(name="EMPLOYE")
public class AbstractEmployeEntity implements UserDetails, Comparable<AbstractEmployeEntity> {
private static final long serialVersionUID = 3577478107563521474L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID_EMPLOYE")
private Long id;
@Column(name= "NOM")
private String nom;
@Column(name = "PRENOM")
private String prenom;
@Column(name = "TYPE_PERSONNE")
private TypeEmploye typePersonne;
@OneToMany(fetch = FetchType.LAZY, mappedBy="referent")
private Set<AbstractClientEntity> listeClients;
@OneToMany(mappedBy="employe", fetch=FetchType.EAGER)
@Cascade(CascadeType.PERSIST)
private Set<RoleEntity> authorities = new HashSet<RoleEntity>();
@OneToMany(fetch = FetchType.LAZY, mappedBy="employe")
private Set<ReunionEntity> reunions = new TreeSet<ReunionEntity>();
@ManyToOne(fetch = FetchType.LAZY)
private AbstractEmployeEntity responsable;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DERNIER_LOGIN")
private Date dernierLogin;
getter and setter....
}
以下是我尝试进行特定映射的方法:
mapper.map(empl, AbstractEmployeDto.class, "employe_simple")
在我的员工集合reunions
不为空的情况下,在此声明中,Hibernate会抛出延迟加载异常......
我想在集合上保持延迟加载,因为我在方法中不需要它们。这就是为什么我使用特定的映射来不映射它们。