I'm trying to find out if there is a way to get a different primary key on a secondary table (that is being setup as a many-to-one relationship) than what is created through the pkJoinColumns. What I need to create is a primary key on the ID in the REGEX table and only have a relationship between the PK on the ELEMENTTYPE table and the FK (ELEMENTTYPEID) on the REGEX table.
When I run the code as it stands now it creates a PK/FK on ELEMENTYPEID in the REGEX table.
Here is an example of what I'm trying to do:
package hello;
import java.io.Serializable;
@Entity
@Table(name = "ELEMENTTYPE")
@SecondaryTable(name = "REGEX",
pkJoinColumns=@PrimaryKeyJoinColumn(name="ELEMENTTYPEID", referencedColumnName="ID"))
public class ElementType implements Serializable {
private static final long serialVersionUID = -6284025093732245698L;
@Id @GeneratedValue
@Column(name = "ID", nullable = false)
private long id;
@Column(name = "ELEMENTNAME", length = 255, nullable = false)
private String elementName;
@Column(name = "DESCRIPTION", length = 255, nullable = false)
private String description;
@Id @GeneratedValue
@Column(name = "ID", table = "REGEX", nullable = false)
private long regexId;
@Column(name = "ELEMENTTYPEID", table = "REGEX", nullable = false)
private long elementTypeId;
@Column(name = "REGEX", table = "REGEX", nullable = false)
private String regexItem;
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "ELEMENTTYPEID", referenceColumnName = "ID", table = "REGEX")
protected ElementType elementType;
public ElementType(long id) {
this.id = id;
}
...
}
|