开发者

How to load entity inside another entity?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜