简体   繁体   English

使用相同的自动生成的ID

[英]Using same autogenerated ID

I have two tables with a one to one relationship. 我有两个具有一对一关系的表。

CONTACT
  id (auto generated)
  ...


CONTACT_ADDRESS
  id
  ...

with Java I have the two classes populated. 使用Java我有两个类。 Contact gets an ID autogenerated. 联系人获取自动生成的ID。 Is there a way to put the same ID in CONTACT_ADDRESS.id while saving it all at once? 有没有办法在一次保存所有ID的同时将相同ID放入CONTACT_ADDRESS.id?

If there isn't one, I will save CONTACT, retrieve that ID and put it into CONTACT_ADDRESS.id. 如果没有,我将保存CONTACT,检索该ID并将其放入CONTACT_ADDRESS.id。

Thanks! 谢谢!

You must use composition. 您必须使用合成。

class Contact {

private long id (auto generated);
@OneToOne
private Contact_Adress contact;// Reference to the other object/table

}

class Contact_Adress {
  private long id(auto generated);

 // the object data here


}

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

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