I'd use one DAO and establish the relationship between your model
objects using annotations. If that doesn't work, write methods in your
DAOs that allow you to manipulate both objects. You can always create
bean definition to CRUD any object with a DAO w/o writing any Java
code.

Matt

On 12/17/07, Alexander Coles <[EMAIL PROTECTED]> wrote:
> Hi,
>
> What would be best practice for using GenericDao with model classes
> and inheritance?
>
> Here are my model classes:
>
> @Entity
> @Table(name = "ITEMS")
> @Inheritance(strategy = SINGLE_TABLE)
> @DiscriminatorColumn(name = "TYPE", discriminatorType = STRING, length
> = 3)
> public abstract class Item
> {
>     private Long id;
>     private String title;
>     ...
> }
>
> @Entity
> @DiscriminatorValue("rel")
> public class Release extends Item
> {
>         ...
> }
>
> @Entity
> @DiscriminatorValue("upd")
> public class Update extends Item
> {
>         ...
> }
>
>
> Should I
>    a) create and declare two separate DAOs in my applicationContext?
> (right now I am extending GenricDao, to add a few additional methods
> beyond the CRUD that's provided):
> public class ReleaseDao extends GenericDao<NewsItem, Long> { ... }
> public class UpdateDao extends GenericDao<NewsItem, Long> { ... }
>
>    b) Use the same GenericDao for both:
> public class ItemDao extends GenericDao<NewsItem, Long>
>
> then in tests and the manager downcast as necessary:
>
> public class ItemDaoTest extends BaseDaoTestCase
> {
>          Release item = (Release) dao.get(-1L);
>          assertEquals(2, item.getAssets().size());
>
>          Asset asset = new Asset();
>         // set some stuff
>
>          item.addAsset(asset);
>          item = (Release) dao.save(item);
>
>          item = (Release) dao.get(-1L);
>          assertEquals("more than 3 assets", 3, item.getAssets().size());
>
>          item.removeAsset(asset);
>          //item.getAssets().remove(asset);
>          item = (Release) dao.save(item);
>
>          item = (Release) dao.get(-1L);
> }
>
>
> Any thoughts would be welcome!
>
>
> Thanks!
>
> Alex
>
> Alexander Coles
> [EMAIL PROTECTED]
> www.alexcolesportfolio.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to