Association Hibernate mapping -


I want to create one-to-one relationship in hibernate (XML mapping).

There are so many examples showing how to do it. A popular example is an address with such a person. Person has got a foreign key to know the table. To be able to make a person's record without any such address, you make the foreign key faucetable.

It does not want me to. I want to contrast my database with a table "merchants" and a table "merchant settings". Each merchant's remittance record is for a merchant and has received a foreign key merchant ID for this. (In this way, I can add the merchant record without any setting.)

In my code, I have a class merchant with the property's settings, what should I see mapping?

(I do not want to use 'component'. The table "Merchant Settings" has got its own private key.)

Does anyone know how to do this?

[Update]

Because now I want to use the same primary key proposed by Kiribsappa GC, I decided to add a foreign key to the table "merchants". I just make it blank, so the recordings of a merchant (examples of person / address) are not required.

This is not ideal, but I can work with it.

Thank you to all.

Although this completely did not match what I wanted, Coribsappa GC's answer seems correct, and I marked it as the accepted answer.

Make merchant as the owner of the relationship as you require needed.

And merchants must have a primary key that is a foreign key from the merchant's table.

So if the above is correct, the mapping is for you

  Merchant Hbm.xml & lt; Hibernate-mapping package = "com.kb.model" & gt; & Lt; Class name = "merchant" & gt; & Lt; Id name = "id" column = "id" & gt; & Lt; Generator class = "identity" /> & Lt; / Id & gt; & Lt; Property Name = "Name" column = "NAME" /> & Lt; One-to-one name = "merchants", "all" /> & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt; Merchantsettings.xml & lt; Hibernate-mapping package = "com.kb.model" & gt; & Lt; Class name = "merchantsettings" & gt; & Lt; Id name = "id" column = "id" & gt; & Lt; Generator class = "foreign" & gt; & Lt; Param name = "property" & gt; Merchant & lt; / Param & gt; & Lt; / Generator & gt; & Lt; / Id & gt; & Lt; One-to-one name = "merchant" constrain = "true" /> & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt;  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -