• Post Reply Bookmark Topic Watch Topic
  • New Topic

Persisting A Parent/Child Structure

 
Jason Ferguson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have the following class that I wish to persist:

public class Item {

private Item parent;
private List<Item> children;

// Getters and setters, equals/hashcode, compareto, etc
}

Now, my backend database is Oracle, and Oracle has the "CONNECT BY" clause for representing this sort of thing.

If I use one of the Oracle dialects, will Hibernate take advantage of this? Or am I better defining a native sql query in my mapping?
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can map self-referring parent/child relationships exactly as other One to Many relationships. In the Caveat Emptor sample Hibernate application, the Category object does just that.

Mark
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason,

HQL doesn't support connect by; see this url (which doesn't say much more than not at this time). Hibernate.org advanced problems.

If you have cases where you need to use connect by for your queries, you'll have to code it yourself. I've had to do it for some high performing search queries, but in general find Hibernate's generated SQL to be sufficient for handling smaller parts of the object graph.
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!