JoinColumn « Map « JPA Q&A

1. How can I ask Hibernate to create an index on a foreign key (JoinColumn)?

class User{

    @JoinTable(name = "user_type", joinColumns = @JoinColumn(name = "user_id"))
    @Column(name = "type", nullable = false)

2. JoinColumn name not used in sql

I have a problem with mapping many-to-one relationship without exact foreign key constraint set in database. I use OpenJPA implementation with MySql database, but the problem is with generated sql scripts ...

3. JPA - Can an @JoinColumn be an @Id as well? SerializationException occurs

I am trying to use an @JoinColumn as an @Id using JPA and I am getting SerializationExceptions, "Could not serialize."

@Table(name = "authorities")
public class UserRole implements Serializable {

 @Column(name = "authority")
 private ...

4. @OneToOne and @JoinColumn, auto delete null entity , doable?

I have two Entities , with the following JPA annotations :

@Table(name = "Owner")
public class Owner implements Serializable
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id")
  private long id;


5. JPA Entities with JoinColumn of two columns

I have this escenario... I have three 4 entities {orderItem, suppliers, supplier, prices}, and they are related like:

OrderItem 1->* suppliers (some one item can have many supplier prices)

Suppliers 1->1 supplier

Suppliers 1->1 ...

6. JPA: difference between @JoinColumn and @PrimaryKeyJoinColumn?

What's the exact difference between @JoinColumn and @PrimaryKeyJoinColumn? You use @JoinColumn for columns that are FKs. A typical column could look like (e.g. in a join table with additional attributes):

@JoinColumn(name = "...")
private ...

7. How to handle @JoinColumn in your own NamingStrategy implementation?

I thought that joinKeyColumnName() handles @JoinColumn, but in reality I could not get it to work. I want to get rid of the necessity to write name="" in @JoinColumn I want ...

8. Why is JPA choosing String for JoinColumn regardless of key types?

Using the EclipseLink JPA2 implementation (not sure if it's the same with the Hibernate implementation) I have a simple structure where an Organization entity has contracts. Here's the sql I exported ...

9. JPA: is @PrimaryKeyJoinColumn(...) the same as @JoinColumn(..., insertable = ?, updatable = ?)?

Can you derive from the JPA spec, if @PrimaryKeyJoinColumn(...), which doesn't have the insertable and updatable parameters, is the same as

@JoinColumn(..., insertable = false, updatable = false)
or ...

10. EclipseLink: multi-column, one-to-one, JPA 2.0 @EmbeddedId using @MapsId fails with read-only on @JoinColumn (derived identities compared)

I have the following design: Valid XHTML Simple logic: Foos uses a multi-column PK to PostAddresses using the same columns (same key). Here are the JPA 2.0 @EmbeddedId mappings (using a nested ...

11. Setting JoinColumn parameters insertable and updatable to null

I have seen a couple of examples on the Internet about using JoinColumn like the way in the example below. Actually, there are two questions I want to ask you about this ...

12. JPA Nullable JoinColumn

I have an entity:

public class Foo {
   private Long id;

   private String username;

   @ManyToOne(cascade = { CascadeType.MERGE }, fetch ...

13. using @ManyToMany relationship without @JoinColumn

i just want to know the difference between using @ManyToMany relationship wit @JoinColumn and using it without @JoinColumn

14. JPA2 JoinColumns JoinColumn name is not being respected. (Hibernate 3.6 and H2)

Here is the reduced snippet, omitting the IdClass details. The issue I am having is the tables definition is:

 client_id int not null,
 personality_trait_id int not null,
 personality_type_id int not null,

15. JPA2:i use a JoinColumn as queryparam to create a query and a exception occurred ,why

    @JoinColumn(name = "want_uid", referencedColumnName = "id")
    private BookUsers wantUid;
    @JoinColumn(name = "sale_uid", referencedColumnName = "id")

16. @OneToOne(optional=false) and @JoinColumn(nullable=false) used together

I've bumped into this example in JPA 2.0 FR Specification, 11.1.37. OneToOne Annotation, page 403:

@JoinColumn(name="CUSTREC_ID", unique=true, nullable=false, updatable=false)
public CustomerRecord getCustomerRecord() { return customerRecord; }
Is there any reason that I should put ...

19. @JoinColumn(nullable = false) necessary?

I read that when you have an @ManyToOne mapping you should underneath it put @JoinColumn(nullable = false). Is it valid to do this even if you arent specifying a column for the join column? Also kinds of situations does this kind of check help? Only one I can think of is if you create the ManyToOne child object and then you ...

20. @OneToOne and @JoinColumn, auto delete null entity , doable?

@Entity @Table(name = "Owner") public class Owner implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private long id; @OneToOne(fetch=FetchType.EAGER , cascade=CascadeType.ALL) @JoinColumn(name="Data_id") private Data Data; } @Entity @Table(name = "Data") public class Data implements Serializable { @Id private ...

21. Simple Bidirectional OneToOne with JoinColumn not working

Hibernate Version 3.5.0.Final (with patch from I've been trying to map a bidirectional @OneToOne association using a @JoinColumn on a non-primary key, without much luck so far. It seems to me that the functionality is missing right now, as somebody supplied a patch to implement the functionality. Even with the patch I couldn't get it to work though. The association ...

22. mappedBy vs JoinColumn and an IndexColumn

I have a OneToMany association between two entities: Newsletter and Section. The order of the Sections within the Newsletter is important and needs to be persisted and I'm using the IndexColumn annotation. Newsletter and Section code snippets are as follows. Newsletter: @OneToMany(mappedBy="newsletter") @IndexColumn(name="sequence") private List

sections = new ArrayList
(); Section: @ManyToOne @JoinColumn(name="newsletter_id", updatable=false, insertable=false) private Newsletter newsletter; However, this didn't persist ...

23. Hibernate not honoring table attribute of @JoinColumn

Newbie Joined: Thu Jul 16, 2009 8:05 am Posts: 1 In my understanding the "table" attribute of the @JoinColumn annotation identifies in what table the join column resides. Hibernate (3.3.2.GA / Oracle) however does not seem to take note of that. Here is a simplified version of my problem mapping: Code: -- DDL (Oracle) : CREATE TABLE demo_config ( ...

25. why @OneToOne( mappedBy ) not using mappedBy's @JoinColumn ?

class A { @Id private long id; private long aUniqueId; @OneToOne( mappedBy="a") private B b; } class B { @Id private long id; private long bUniqueId; @OneToOne @JoinColumn( name="aId", referencedColumnName="aUniqueId" ) ...

26. table attribute in @JoinColumn causes annotation exception

Newbie Joined: Wed Feb 02, 2011 10:05 am Posts: 1 Hi, I am running into a strange issue. I am using intelliJ IDEA to automatically create annotated classes from a simple (personal tutorial) database schema consisting of three tables: address, state and country. The three annotated classes are generated accordingly (and according to the api), but when I try to create ...

27. Audited class with JoinColumn referencedColumnName not pk

Hi all, I have a Audited class with a @ManyToOne join between two tables using a non pk column, like this: Code: @Audited @Entity public class A { @Id @GeneratedValue private long id; @ManyToOne ...

28. JoinColumn: using Parent class field

@Entity @Table(name="TABLE2") @PrimaryKeyJoinColumn(name = "ID") class SubClass extends Parent{ ... ... /** *A List of CompositeElement objects. ...

29. Cast and joincolumn

30. @JoinColumn settings

31. Joincolumn vs Jointable

33. How to specify a constant value for a JoinColumn?

This seems like a pretty common thing to want to do but I haven't seen any example of how to accomplish this: Basically, I want to have a JoinColumns annotation where I specify a constant value for one of the columns. Here's a simple example to illustrate... basically I want to bind a Person object's homeAddress value to the Address table ...

34. JoinColumn not-nullable for manyToOne and oneToOne

This question comes up from time to time in the Hibernate forums. According to Gavin King, one of the men behind Hibernate, the way to do this is to map 0 to null is to write a UserType that transforms 0 to null, and use that custom UserType as the identified type. Hibernate will not create a schema with default values, ...

35. @Any does not work: @Any requires an explicit @JoinColumn(s)

@Entity public class MyEntity implements Serializable { ... private Property mainProperty; @Any(metaColumn = @Column(name = "property_type"), fetch = FetchType.EAGER) @AnyMetaDef(idType = "integer", metaType = "string", metaValues = { @MetaValue(value = "S", targetEntity = StringProperty.class), @MetaValue(value = "I", targetEntity = IntegerProperty.class) } ) ...

36. JPA / Hibernate delete_orphan while joincolumn updatable

Hibernate cannot find the entity it's about to delete when I'm using the delete_orphan annotation in combination with an updatable foreign key. Both entities are versioned for optimistic locking. When I inspect hibernates sql it seems it first updates the child entity by setting to foreign key to null. Afterwards the delete_orphan is doing it's work with the resulting delete statement. ...

37. order of @JoinColumn annotations seems to matter

38. @JoinColumn doesn't gewnerate foreign key constraints

specs: hibernate, anno, em Hi, First of all, I have read a lot of docs (maybe I missed something :( ). Does referencedColumnName attribute of @JoinColumn need to refer only to an ID of an entity to generate a foreign key? What if I want to refer to a unique key but is not an ID (but a ...