简体   繁体   中英

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

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-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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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