Thursday 15 January 2015

java - The concept for one-to-one mapping. Explain the mapping -


How do define one-by-one relationship between 2 classes? I think I'm going somewhere wrong, ideologically. I do not know what this is, but it is.

We think that country and prime minister :

 

I was trying this:

  & lt; Class name = "pojo.ountry" table = "country" & gt; & Lt; Id name = "c_id" & gt; & Lt; Generator class = "increment increase" /> & Lt; / Id & gt; & Lt; Property Name = "name_c" /> & Lt; One-to-one class = "pojo.PM" name = "name_pam" /> & Lt; / Square & gt; & Lt; Class name = "pojo.PM" table = "pm" & gt; & Lt; Id name = "c_id" & gt; & Lt; Generator class = "increment increase" /> & Lt; / Id & gt; & Lt; Property name = "name_pam" /> & Lt; / Square & gt;   

But this effusive mapping does not do anything to generate an exception during the running time. It says that property can not be found inside name_pm in country class! But does it search within the country category. It should search within the PM class

Help me to complete my one-by-one mapping between 2 classes I have some time I am trying for it.

Java code:

country

  public class country {Private Int c_id; Private string name_c; Public int getC_id () {return c_id; } Public Zero setC_id (int c_id) {this.c_id = c_id; } Public string getName_c () {return name_c; } Public Zero setName_c (string name_c) {this.name_c = name_c; }}   

Prime Minister

  The Prime Minister of the Public Sector {Private Ent C_id; Private string name_pair; Public int getC_id () {return c_id; } Public Zero setC_id (int c_id) {this.c_id = c_id; } Public string getName_pm () {return name_pm; } Public Zero setName_pm (string name_pm) {this.name_pm = name_pm; }}   

The problem is in the connection between your XML mapping and your java code.

If you specify

  & lt; One-to-one class = "pojo.PM" name = "name_pm" /> Your name must be named "name_pm" in   

your country POJO.

You do not have any such fields.

If your country class has an area for the prime minister, then the name of that area should be used here.

If neither of the others are references to the class, you have to add one.

What I will do with your code, add the field to the country and use its name in the mapping.

  public class country {Private Ent C_id; Private string name_c; Private PM c_pm; Public int getC_id () {return c_id; } Public Zero setC_id (int c_id) {this.c_id = c_id; } Public string getName_c () {return name_c; } Public Zero setName_c (string name_c) {this.name_c = name_c; } Public PM getC_pm () {Return c_pm; } Public Zero setC_pm (PM c_PM) {this.c_pm = c_pm; }}   

Mapping:

  & lt; Class name = "pojo.ountry" table = "country" & gt; & Lt; Id name = "c_id" & gt; & Lt; Generator class = "increment increase" /> & Lt; / Id & gt; & Lt; Property Name = "name_c" /> & Lt; One-to-one class = "pojo.PM" name = "c_pm" /> & Lt; / Square & gt;   

Disclaimer:

I have not tested any of these, and I'm not sure how mapping should be done If it seems like sharing a test version with the shared primary key, then I can happily give another answer or turn it on to "Community Wiki".

No comments:

Post a Comment