Question

I am using Hibernate, Spring and Dozer in my project .

My Problem is that that I am unable to Load Lazy fetching Collection(List). I am using Dozer to convert entity class into (Dto) class. I think Dozer user Know these things.

When I debug then I get all data from DB in entity class but when I converted into Dto through Dozer I get null in Collection which is Lazy Fetched.

Please help me out here. Thanks in advance!

I am unable to get Developer List when I Converted entity to Dto. I have exact Dto classes name Developer and Founder and I map these in String Configuration File. I tried @Select On join table then its loaded and working fine but I don't want that way . If I have to make extra function in my servicemanager class then help me .

@Entity
@Table(name = "table")
public class Founder {

    @Id
    @Column(name = "foun_id")
    @GeneratedValue(generator = "uuid")
    private String id;

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, optional = false)
    @JoinColumn(name = "reg_address_id")
    private Address registeredAddress;


    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(name = "jointable", joinColumns = { @JoinColumn(name = "foun_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "dev_id", nullable = true) })
    private List<Developer> developer;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Address getRegisteredAddress() {
        return registeredAddress;
    }

    public void setRegisteredAddress(Address registeredAddress) {
        this.registeredAddress = registeredAddress;
    }

    public List<Developer> getDeveloper() {

        return developer;
    }

    public void setDeveloper(List<Developer> developer) {
        this.developer = developer;
    }

}

@Entity
@Table(name = "tbl")
public class Developer {

    @Id
    @Column(name = "dev_id")
    @GeneratedValue(generator = "uuid")
    private String id;

    @Column(name = "file_number")
    private String fileNumber;

    @Column(name = "flat_info")
    private String flatInfo;

    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, optional = false)
    @JoinColumn(name = "address_id")
    private Address address;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFileNumber() {
        return fileNumber;
    }

    public void setFileNumber(String fileNumber) {
        this.fileNumber = fileNumber;
    }

    public String getFlatInfo() {
        return flatInfo;
    }

    public void setFlatInfo(String flatInfo) {
        this.flatInfo = flatInfo;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
}
Was it helpful?

Solution

As I wrote in comment, most likely Dozer access fields of Founder and Developer directly and ignoring the getters. As Hibernate create proxies for lazy loading, this ends up with empty collections after conversion. Consider changing your class to add mapping information to getters instead of fields.

This question might be useful for you - Is it possible to configure Dozer such that by default fields are rather accessed directly that through setter-/getter method

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top