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: JPA Annotations for SecondaryTable and Primary Key
PostPosted: Wed Dec 10, 2008 1:43 pm 
Newbie

Joined: Wed Dec 10, 2008 11:38 am
Posts: 1
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;
}

...
}


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.