开发者

Hibernate one-to-one and one-to-many

开发者 https://www.devze.com 2023-04-06 02:54 出处:网络
I currently have a one-to-many relation between 2 table: I have: Table A (id, ...) Table B (tableAId, ...) (has no id of it\'s own).

I currently have a one-to-many relation between 2 table: I have:

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

In the mapping this is done using <list>.

The issue I am having, is that I have to add another one to one relationship from A to B. Something like this:

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-t开发者_运维技巧o-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?

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

0

精彩评论

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