I am learning Hibernate from the tutorials on JBoss website. I have a confusion in a code example located here.
There is a Cat class code at 4.1. A simple POJO example.
This Cat class has a reference to his mother as private Cat mother;
Q1. If the class has an identifier property as id, then wouldn’t it be better to store the cat’s mother’s id instead of cat’s mother object.
means instead of
private Cat mother;
wouldn’t it be better to have
private long motherId;
`
That’s what hibernate implicitly does for you.
The good thing about
ORMis that it completely hides implementation caveats due to the fact that you are working on a RDBMS instead that with plain objects. You can usemotherasCatwithout bothering about the fact that its relation it’s expressed by anidinternally.