I have 3 tables: table 1 has primary key table1Id, has one to many relationship with table3 table 2 has primary key table2Id, has one to many ralationship with table 3 table 3 has composite primary key table3Id = (table1Id,table2Id)
My entities are as follows:
public class Table1 {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "table1Id") private Integer table1Id;
@OneToMany(mappedBy = "table3Id.table1id", cascade = CascadeType.ALL) private Set<Table3> t3 = new HashSet<Sample>(); ---- etc. etc }
public class Table2 {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "table2Id") private Integer table2Id;
---- etc, etc }
public class Table3 { @EmbeddedId private Table3PK table3Id;
--- etc, etc } @Embeddable public class Table3PK implements Serializable {
private static final long serialVersionUID = -9059611979460128106L;
@NotNull @ManyToOne @JoinColumn(name = "table2Id", referencedColumnName = "table2Id") private Table2 table2;
@NotNull @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "table1Id", referencedColumnName = "table1Id") private Table1 table1; ----- etc. etc }
When I try to commit an entity Table1, I get a null pointer exception because the table2Id is null. In other words, it is not inserting a new row in table2 correctly. I think my mappings are screwed up. Any ideas? Thanx
|