I tried to learn on my own, but soon started to realize that by the end of endless books, I will know all the @Entity etc. low level stuff without ever understanding top level.
So my understanding is:
- We usually declare DAO interface where we define all the methods to perform on Domain Model.
- Secondly we write Domain Model to represent entity in Database.
- We write DAO implementation class which can use Hibernate, JPA , JDBC or whatever miracles we have out there and which implements our DAO interface.
(wiring up altogether with Spring)
My questions referring to points above:
We write single DAO interface per Domain Model? If we have cross-cuting behavior where participation involves more than one Domain Model we declare new pair DAO interface-implementation and call it accordingly? As example: "Customer orders from Stock, Stock checks whether Item is available -> confirms if it is" where would that go?
How Hibernate interacts with MVC? Are there any important aspects to be aware of?
In a book I noticed:
Overriding Equals and Hashcode
"In simple scenario, Hibernate is able to maintain entity equivalence without requiring any special changes to the domain objects themselves. However, if your application requires that you add entites to Java collections, such as java.util.Set, or you plan to work with detached entities, you will probably need to override the default equals() and hashCode() methods for your domain objects"
Maybe I don't understand it really well, what are detached entities? Are those the one we've taken out of Hibernate context - effectively just collections of classes?
What I want is safely to do Hibernate its work, then return me a Model which I would give to Servlet and which will delegate it to appropriate View. We extract that model by means of simple return from DAOimpl class methods or is it somewhat tricky?
If I am to do persistence tier without ORM framework, just with plain JDBC, what are my problems? I've heard that Hibernate has some smart session which handles concurrent requests, so what will happen with JDBC?
Where does business logic resides in? Is it DAOimpl classes?
I am sorry if some of my questions are mishaps, I appreciate any critic and correction.
Thank You.