I\'ve got some problem with hibernate @OneToMany
mapping. It goes like here
@Entity
@Table(name = \"albums\")
@SequenceGenerator(name = \"ALBUMS
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;
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
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