I have a problem joining tables to retrieve information
I have three tables:
city
(city_id, name) - information about the开发者_如何学编程 city.state
(state_id, name) - information about statecity_state_map
(city_id, state_id)
and I have two hibernate entities: City
, State
.
I want to load State
from City
entity to get the State
of the City
.
I have no idea how to do it for three tables. I got many tutorials that showed how to join two tables.
You need a @ManyToOne
mapping. For example:
@ManyToOne
private State state;
(by default hibernate's naming strategy will look for state_id
. Otherwise you may need to specify @JoinColumn
)
精彩评论