-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help with complex composite key
PostPosted: Tue May 04, 2010 10:43 pm 
Newbie

Joined: Tue Jun 02, 2009 12:35 am
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.