Calling one DAO from another DAO?

前端 未结 3 996
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 14:39

Can this ever make sense?

Say I need to fetch an object from the DB which has a relation to another object (represented by a foreign key in the DB, and by a composit

3条回答
  •  半阙折子戏
    2020-12-30 15:05

    In reading this I can only conclude that most likely, you're doing it wrong.. ;)

    If you setup your mappings right between ObjectA and ObjectB (could be OneToOne, OneToMany or ManyToMany), Hibernate will (lazy)load the reference from A to B automatically. This will eliminate the need to query the second DAO, and set the ObjectB reference in ObjectA.

    Take this one step further and you might not even need the DAO for ObjectB!

提交回复
热议问题