I use Orika to map Hibernate entities to DTO objects in web service calls. These objects have @OneToMany and @ManyToOne relationships in them for parent-child relationships. In addition, I use Spring JPA to create these objects.
When mapping a Hibernate object to a POJO DTO class, the map () method loads all lazy attributes.
@Entity
@Table(name="folders")
public class FolderEntity {
@Id
@GeneratedValue
private int id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="consumerId")
private ConsumerEntity consumer;
public class Folder
private int id;
private User consumer;
Folder folder = mapper.map(some_folder_entity, Folder.class);
In this case, matching consumer attributes causes Hibernate to load the child, which I don't want.
I, although HibernateUnenhanceStrategy should have solved this problem by deleting the Hibernate proxy, but it is not, or I am doing it wrong.
@Component
public class MapperFacadeFactory implements FactoryBean<MapperFacade> {
public MapperFacade getObject() throws Exception {
DefaultMapperFactory.Builder factoryBuilder = new DefaultMapperFactory.Builder();
factoryBuilder.unenhanceStrategy(new HibernateUnenhanceStrategy());
DefaultMapperFactory factory = factoryBuilder.build();
MapperFacade facade = factory.getMapperFacade();
return facade;
}
, , , -, -.
, CustomMapper, , , , -, Orika.
.