Hibernate reverse engineering

I have a structure where the main table is USER, other tables include CATEGORY (contains user_id).

What I got after the standard reverse engineering procedure:

  • the User class contains a set of categories,
  • the class category did not contain a foreign key (user_id), but contained a User object.

Why doesn't it contain a foreign key as a property of a class?

And how can I join these two tables in HQL without this glue? HQL - please explain this part.

+3
source share
3 answers

Why doesn't it contain a foreign key as a property of a class?

Hibernate Object -Relational Mapping, Hibernate (.. ) ( ). Hibernate , - ( - ). ( ) :

alt text http://img251.imageshack.us/img251/6335/110b578b.png

HQL ?

, ( ). (. 14.3. ):

from Category as category join category.user as user

, HQL : (. 14.4. ). . join, -:

from Category category where category.user.id =: id
+3

Hibernate . Java , . Category ( a) User, FK. User Category FK User Hibernate.

, Hibernate SQL-, FK. HQL, , Hibernate .

: HQL:

from Category as category inner join fetch category.user as user

, .

. Hibernate Reference, 5 7.

+3

Péter Török: .

, , , , FK?

FK? category.getUser(). getId(); , Category.

0

Source: https://habr.com/ru/post/1736296/


All Articles