简体   繁体   English

一对一和一对多休眠

[英]Hibernate one-to-one and one-to-many

I currently have a one-to-many relation between 2 table: I have: 我目前在2个表之间有一对多关系:我有:

Table A (id, ...)
Table B (tableAId, ...) (has no id of it's own).

In the mapping this is done using <list>. 在映射中,这是使用<list>完成的。

The issue I am having, is that I have to add another one to one relationship from A to B. Something like this: 我遇到的问题是,我必须从A到B添加另一个一对一的关系。

class A {
    public B b; // new part
    public List<B> bs; // already existing part.
}

I have a boolean column in the table by which I should differentiate between the one-to-one and one-to-many. 我在表中有一个布尔列,通过该列我应该区分一对一和一对多。 I'm not sure how to write the hibernate mapping for these tables. 我不确定如何为这些表编写休眠映射。 Could any of you help me out with this? 你们中的任何一个都可以帮我吗?

I think you can do this by using 'mappedBy', have you tried that? 我认为您可以通过使用“ mappedBy”来做到这一点,您是否尝试过?

http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-association http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-association

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM