Olgun Kaya
Olgun Kaya

Reputation: 2579

JPA JoinColumn does not work

I have started with an example from a book. It was really a dummy oriented one and I am having a problem with the code the book gave.

Here is the code;

@Entity
public class Customer {
@Id
@GeneratedValue
private Long id;
private String firstName;
private String lastName;
private String email;

@OneToOne (fetch = FetchType.LAZY,
           cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "address_fk")
private Address address;
//getter, setter, Constructor

--//-------------------------------------

@Entity
public class Address {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private String id;
private String city;
private String street;
private String number;

In here it is complaining on the JoinColumn annotation. It says the column address_fk is not found.

Is this an IDE related issue? Am I missing something?

Edit : No table yet created in the DB. I am expecting them to be seen on the DB automatically by my persistence.xml

<property name="eclipselink.ddl-generation" value="create-tables"/>

Upvotes: 1

Views: 2003

Answers (1)

Mikko Maunu
Mikko Maunu

Reputation: 42074

Using @JoinColumn annotation to specify foreign column name to be address_fk instead of default address_id is fine.

What likely does not to work is @GeneratedValue with String. According specification only integral types as generated primary keys are portable.

Upvotes: 2

Related Questions