Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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: 17278
6
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic