开发者

How to load entity inside another entity?

开发者 https://www.devze.com 2023-03-23 00:26 出处:网络
I have a problem joining tables to retrieve information I have three tables: city (city_id, name) - information about the开发者_如何学编程 city.

I have a problem joining tables to retrieve information

I have three tables:

  1. city (city_id, name) - information about the开发者_如何学编程 city.
  2. state (state_id, name) - information about state
  3. city_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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号