Hi, I think there is no common pattern. It solely depends on your usage scenario. If you don't need to use a reverse side of the relationship in your business logic, I would recommend removing that part. Mind some of the intricacies though e.g. if you remove the parent reference field in child and not specify in parent that this column must _not_ be null, you can get Exception with some persistence providers: http://stackoverflow.com/questions/12755380/jpa-persisting-a-unidirectional-one-to-many-relationship-fails-with-eclipselin
Speaking from experience, Hibernate is very "tolerant" compared to e.g. OpenJPA or EclipseLink Greetings, Greg 2014-03-07 10:15 GMT+01:00 Yahoo <[email protected]>: > Hello Greg, > Your solution works fine. > With a lot of Lazy Loading and circular relations > I have the idea to include the decision which relations should be really > loaded > and which should be nulled > in the Dao.Do you know if there is already a professional solution for > this usage? > > > Am 04.03.2014 23:47, schrieb gelo1234: > > > Another kind of "hack" (if you cannot modify entity sources and they are > not external .xml files) would be setting all child objects' parent > references to null _before_ serializing that data. > > Lets say you got: Author and Book entites with One-To-Many relationship. > > You retrieve the entities from db and _before_ URLResponse, you modify > all Books entities with null reference to parent(Author) entity: > > > List<Author> authors = hibernateDAO.getAllAuthors(); > > // make sure hibernate session is closed and authors objects are > _detached_ > // with full data structure -> FetchType.EAGER > > for (Author author: authors) { > List<Book> books = author.getBooks(); > for (Book book: books) > book.setAuthor(null); > } > > Now you can safely call URLResponse with authors (they don't contain any > circular references anymore). > > Greetings, > Greg > > > > 2014-03-04 23:00 GMT+01:00 gelo1234 <[email protected]>: > >> Hi >> >> Can you debug where exactly a problem with circular references exists ? >> Is it during serialization of your data ? StringTemplate? IOUtils? >> >> Many serialization techniques/libs do have problems with such >> references, be it JAXB or GSON. For JAXB you can setup @Transient >> annotation. >> >> How about a quick fix, that removes one side of relationship in >> Hibernate entities making it uni-directional instead of bi-directional e.g. >> reverse side ? >> >> Greetings, >> Greg >> >> >> >> 2014-03-04 22:29 GMT+01:00 Yahoo <[email protected]>: >> >> I am using Hibernate 4.1.8-Final and cocoon 3.0.0-beta-1-SNAPSHOT. >>> But why you ask? >>> Am 03.03.2014 08:09, schrieb Francesco Chicchiriccò: >>> >>> On 03/03/2014 04:36, Yahoo wrote: >>>> >>>>> I am using cocoon RestController to present my Hibernate Mysql data >>>>> in pdf files. >>>>> The Hibernate structure has cirular relationships, so when I give the >>>>> structure to the URLResponse there are endless StringBuilder calls.Do you >>>>> have an idea how to solve this problem.One idea would be to present the >>>>> data in an non Hibernate bean without cicular relationships. But may be >>>>> there is an opportunity to avoid new beans. >>>>> >>>> >>>> Hi, >>>> such problems arise every time JPA (or other persistence frameworks) >>>> entities are published (via REST in your case) without any transformation >>>> (the DTO pattern): I am afraid there is any cleaner solution than >>>> converting your Hibernate entities into something simpler. >>>> >>>> BTW: which version are you using? >>>> >>>> Regards. >>>> >>>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [email protected] >>> For additional commands, e-mail: [email protected] >>> >>> >> > >
