ids for this class must be manually assigned before calling save()

做~自己de王妃 提交于 2019-11-30 14:21:04

First - it can't generate them because you didn't tell it how to do it. Use @GeneratedValue and choose the strategy you want.

Then - you can't have two @Id fields. If you want a composite id use @EmbeddedId or @IdClass

You are using two primary keys in one table and one of the keys is also a primary key in another table. The simple solution is to remove the one of the primary keys which is also the foreign key

Parvej Solkar

I was facing the same problem, but what worked for me was

B oB = new B();        // Class B contains two objects of class A

A oA1 = new A();
oA1.Name = "First";
oB.PlaceA1 = oA1;

A oA2 = new A();
oA2.Name = "Second";
oB.PlaceA2 = oA2;

Changed to

B oB = new B();        // Class B contains two objects of class A

A oA1 = new A();
oA1.ID = 1;            // This was missing(Manual Assignment of ID field)
oA1.Name = "First";
oB.PlaceA1 = oA1;

A oA2 = new A();
oA2.ID = 2;            // This was missing(Manual Assignment of ID field)
oA2.Name = "Second";
oB.PlaceA2 = oA2;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!