I
I
Igor Petrov2011-07-11 10:14:20
Java
Igor Petrov, 2011-07-11 10:14:20

Hibernate. What are link collections for?

Hey Habr!

When rummaging through someone else's code, I often see a similar structure ( here , for example):

<set name="busses" lazy="false">
   <key column="route_id"/>
   <one-to-many class="logic.Bus"/>
</set>

* This source code was highlighted with Source Code Highlighter.

What "it" does, I know - everywhere it is painted a thousand times. Interested in why this is necessary? After all, it seems normal to work without these connections. Does this somehow simplify the functionality or is it impossible to work without it at all?

Thank you all in advance for your participation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Ganesh, 2011-07-11
@Ganesh

Before learning Hibernate, it is better to first get acquainted with SQL itself, then it will become much clearer to you, and Hibernate has a decent manual, which is more than enough to start working as a framework

A
antalus, 2011-07-11
@antalus

In order for Hibernate to do joins and subqueries for you. Those. you work with objects as always:
call route.getBusses() to get a list of buses on the current route, then you can change this Set as required by the business logic - everything will be automatically saved in the database. That is, such mappings are a common practice for ORM.
Instead of calling a separate DAO method that will pull out a list of buses by route id and then save possible modifications to this list again by calling another method.
You can work without these connections - but then why do you need an ORM? If you think that Hibernate does “too much” for you, I advise you to pay attention to myBatis www.mybatis.org/ , an introductory series of articlesjava.dzone.com/articles/getting-started-ibatis-mybatis

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question