0

Let's say I have following POJO's using Hibernate.

public class User {

   private String userName;
   private String name;
   private String surname;
   private List<Blog> blogList;

   //All getters and setters are found here and assume they're generated.
}

public class Blog {
    private String title;
    private String content;
    private User author;
    private Date datePublished;
    private Date dateLastModified;

    //All getters and setters have been generated (by Eclipse or NetBeans)
}

As stated here Hibernate prevents infinite loops while data retrieval. My application architecture uses two different types of transfer objects. One for backend and one for frontend purposes. In the middle of both a converter translates them. Here I am encountering the problem hibernate prevented earlier.

One solution could be changing relation to unidirectional. But is there another solution that lets me use a bidirectional approach?

Community
  • 1
  • 1
Sven
  • 6,288
  • 24
  • 74
  • 116

1 Answers1

0

There are two solutions:

  • don't use DTOs, and transfer the Hibernate entities themselves. They're POJOs, and can be serialized if you make them implement the Serializable interface
  • fix the conversion code. Either make the association unidirectional in the DTOs, or make sure to convert the bidirectional association properly. Hibernate can do it, so you should be able to do it as well.
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • If I knew how to do it, I wouldn't ask here :-) – Sven Jan 17 '12 at 15:08
  • That's not what you asked. You asked if there were other solutions than making the association bidirectional. If you want us to tell you how to fix your conversion code, show us the conversion code. – JB Nizet Jan 17 '12 at 15:10