Assuming the following mappings are provided:
Another approach you could take is to define the FK with your B mapping rather than the A mapping. I've added the JPA code, you'd have to translate this to your hibernate mapping file if you're not using annotations.
@Entity
public class B
{
private long id;
private List aList;
@Id
@Column( name = "ID" )
public long getId()
{
return id;
}
@OneToMany
@JoinColumn( name = "B_ID" )
public List getAList()
{
return aList;
}
public void setId( long id )
{
this.id = id;
}
public void setAList( List aList )
{
this.aList = aList;
}
}
A.java would not look like this:
@Entity
public class A
{
private long id;
private long idOfB;
@Id
@Column( name = "ID" )
public long getId()
{
return id;
}
@Column( name = "B_ID" )
public long getIdOfB()
{
return idOfB;
}
public void setId( long id )
{
this.id = id;
}
public void setIdOfB( long idOfB )
{
this.idOfB = idOfB;
}
}