Mark
Mark

Reputation: 69920

Hibernate GenericDAO for parent/child relationships and DAO/DTO patterns

I'm looking for a Generic DAO implementation in Hibernate that includes parent/child relationship management (adding, removing, getting children, setting parents, etc).

Actually the most used generic DAO on the web is the one I found on jboss.org.

And also, i was looking for some DAO/DTO sample implementations and design patterns.

Do you know some good resources out there?

Upvotes: 1

Views: 5249

Answers (2)

Pascal Thivent
Pascal Thivent

Reputation: 570325

I'm looking for a Generic DAO implementation in Hibernate that includes parent/child relationship management (adding, removing, getting children, setting parents, etc).

I would keep the parent/child links management at the entity level (not all entities have parent/childs) but I would create link management methods on them to set both sides when working with bi-directional links as described in 1.2.6. Working bi-directional links.

Actually the most used generic DAO on the web is the one I found on jboss.org.

There are several projects with samples on Google code. I'd suggest to check:

  • generic-dao - JPA Data Access Object Toolkit
  • daofusion - Java based DAO pattern implementation using JPA / Hibernate.
  • hibernate-generic-dao - Generic DAO implementation: extendable, detailed search, remote service interface

Upvotes: 2

Behrang Saeedzadeh
Behrang Saeedzadeh

Reputation: 47913

Parent/Child relationships are a special kind of one-to-many relationships, and they do not require a special DAO to interact with. You simply write code like:

Parent p = new Parent();
Child c1 = new Child();
Child c2 = new Child();
// populate c1 and c2
p.addChild(c1);
p.addChild(c2);
childDao.save(c1);
childDao.save(c2);
parentDao.save(p);

There's a section of the Hibernate doc that actually shows an example parent/child implementation: Chapter 21. Example: Parent/Child

If you prefer to use annotations and/or Hibernate/JPA, have a look at: Taking JPA for a Test Drive

Upvotes: 0

Related Questions