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

后端 未结 3 703
情书的邮戳
情书的邮戳 2021-01-02 17:38

I\'ve got some problem with hibernate @OneToMany mapping. It goes like here

@Entity
@Table(name = \"albums\")
@SequenceGenerator(name = \"ALBUMS         


        
3条回答
  •  庸人自扰
    2021-01-02 18:14

    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;
    

提交回复
热议问题