I'm having a problem figuring out how to handle the interaction between entities on an application using JDBC. Previously I've used Hibernate and that wasn't a real issue because almost everything was solved either automatically or via annotations. Now, using JDBC there's not such magic.
Lets say I have this classes:
class A{
private String name;
private List<B> bs;
private C c;
}
class AService{
private ADao aDao;
void save(A a){
aDao.persist(a);
}
}
class ADao{
void persist(A a){
//open connection and autocommit false
//persist C
//persist B's
//persist A
//commit
}
}
B and C have their respective DAO and Services.
Now, as far as I know, you shouldn't mix DAO's with each other... meaning I shouldn't use in ADao the BDao and/or CDao, just their services.
If this is true, how am I suppose to achieve the desired behaviour? That I can, transactionally, persist multiple entities? Services shouldn't know anything about connection or whatsoever... those are detail implementations that I cannot propagate to the business layer.
So far I haven't found anything online... all the examples are with a single entity, and the only other solution I could come up with was to simply duplicate the code on my other DAO's.
I'd really appreciate any help you can provide, as well as books or good material to read about this. I've found some books about jdbc.. but quite frankly they aren't that good... some of them even propagate the DAO to the presentation layer.. :/