0

I am using eclipselink 2.5.1.

Let's say I have these two class.

JAVA

@Entity
public class Car implements Serializable {
    @EmbeddedId
    protected CarPK carPK;

    private String color;
    @ManyToOne(fetch = FetchType.LAZY)
    private Manufacturor manufacturor;
    //constructors, getters & setters...
}

@Embeddable
public class CarPK implements Serializable {
    @NotNull
    private int idManufacturor;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date date;
    //constructors, getters & setters...
}

Car has a composite primary key (idManufacturor and date) and idManufacturor is also a foreign key referencing the class Manufacturor.

I'm having issue with the mapping. EclipseLink understand the manufacturor object as a column in my Car table.

Error

Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: invalid column name : 'manufacturor'.

I know the problem will be solved if I add a column manufacturor FK but it would be repeating.

Please feel free to ask for any precision if I'm not clear enough.

Thank you for your help.

Nordine
  • 824
  • 7
  • 25

1 Answers1

1

Add the JoinColumn Annotation

@JoinColumn(name = "id_manufacturor", referencedColumnName = "id")

Name is the FK column name in your database (not entity).

The referencedColumnName "id" must correspond to the defined id in manufacturer table.

tak3shi
  • 2,305
  • 1
  • 20
  • 33
  • Thanks for your help, I tried adding the annotation but I'm having this error: Exception Description: Multiple writable mappings exist for the field [CAR.IDMANUFACTUROR]. Only one may be defined as writable, all others must be specified read-only. – Nordine Mar 21 '17 at 12:23
  • Add updatable=false and insertable=false to the JoinColumn anotation. – tak3shi Mar 21 '17 at 12:25