Why would an empty record be created if the object is already
instantiated and initialized before calling create()? In my current
design, here's a simplified flow:
public class ItemDaoJdbc extends BaseDaoImpl<Item, Integer> implements
ItemDao {
...
@Override
public int create(Item anItem) throws SQLException {
DaoManager.createDao(connectionSource,
Aggregate.class).create(anItem.getAggregate());
return super.create(anItem);
}
}
and the client uses the create() as follows:
Item anItem = new Item(a,b,c,...); // Item()'s constructor
instantiates and initializes its aggregate class
itemDao.create(anItem); // Calls create method shown above.
As far as how to implement this goes, after doing a bit more research
into this, I see that Hibernate uses these kinds of annotations. I
don't think it makes sense to reinvent the wheel, so sharing the same
notation would be great. OrmLite is my first Orm experience, so I'm
not sure exactly how these are used in Hibernate, but here's the list
of cascade cascade attributes.
■ cascade="none", the default, tells NHibernate to ignore the
association.
■ cascade="save-update" tells NHibernate to navigate the association
when the
transaction is committed and when an object is passed to Save() or
Update()
and save newly instantiated transient instances and persist changes to
detached
instances.
■ cascade="delete" tells NHibernate to navigate the association and
delete persistent
instances when an object is passed to Delete().
■ cascade="all" means to cascade both save-update and delete, as well
as calls to
Evict and Lock.
■ cascade="all-delete-orphan" means the same as cascade="all" but, in
addition,
NHibernate deletes any persistent entity instance that has been
removed
(dereferenced) from the association (for example, from a collection).
■ cascade="delete-orphan" has NHibernate delete any persistent entity
instance
that has been removed (dereferenced) from the association (for
example, from
a collection).
I hadn't thought about cascading deletes and updates too, which will
also be useful. It would be nice if these were supported on both
collections and individual fields.
Thanks,
Jeff