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]

Reply via email to