Re: Mapping Compound PK with FK Reference? [message #758004] |
Thu, 17 November 2011 21:30 |
Shelli Orton Messages: 101 Registered: September 2009 |
Senior Member |
|
|
Through much trial and error, here is the correct setup:
@Entity
public class Child
{
private ChildPK childId;
private String string1;
public Child()
{
// empty constructor
}
@EmbeddedId
public ChildPK getChildId()
{
return childId;
}
public void setChildId(ChildPK childId)
{
this.childId= childId;
}
@Column(name = "STRING1")
public String getString1()
{
return string1;
}
public void setString1(String string1)
{
this.string1 = string1;
}
// bi-directional many-to-one association to Parent
@ManyToOne
@JoinColumn(name = "PARENT_NAME", updatable=false, insertable=false)
public Parent getParent()
{
return this.parent;
}
public void setParent(Parent parent)
{
this.parent = parent;
}
}
@Embeddable
public class ChildPK implements Serializable
{
private static final long serialVersionUID = 1L;
private String name;
private String parentName;
public ChildPK()
{
//empty
}
@Column(name = "NAME")
public String getName()
{
return name;
}
public void setName(String name)
{
this.name= name;
}
@Column(name = "PARENT_NAME")
public String getParentName()
{
return parentName;
}
public void setParentName(String parentName)
{
this.parentName= parentName;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02217 seconds