I use JPA interface, provider - Hibernate. One entity have embedded primary key:
@Entity
@Table(name = "CD_CONTROL")
public class CdControl extends BaseDAO<CdControl> {
@EmbeddedId
private CdControlPk id;
@Column(name = "CD_CONTROL_NAME")
private String cdControlName;
// ...
public CdControlPk getId() {
return id;
}
public void setId(CdControlPk id) {
this.id = id;
}
// ...
}
In embedded primary key I defined database type of columns type of properties in columnDefinition attribute of @Coloumn annotation:
@Embeddable
public class CdControlPk implements Serializable {
@Column(name="CONTROL_KEY", columnDefinition = "RAW")
private String controlKey;
@Column(name="CONTROL_OWNER_KEY", columnDefinition = "RAW")
private String controlOwnerKey;
// ...
}
In database associate coloumn have type RAW. It id used database Oracle 10g. I have entity which have ManyToOne assosiation with CdControl:
@Entity
@Table(name="CD_PROPERTY_VALUE")
public class CdPropertyValue extends BaseDAO<CdPropertyValue> implements Serializable {
@EmbeddedId
private CdPropertyValuePK id;
@Column(name="VALUE")
private String value;
//bi-directional many-to-one association to CdControl
@ManyToOne
@MapsId("id")
@JoinColumns({
@JoinColumn(name = "CONTROL_OWNER_KEY", referencedColumnName ="CONTROL_OWNER_KEY",
columnDefinition="RAW", insertable=false,updatable=false),
@JoinColumn(name = "CONTROL_KEY", referencedColumnName = "CONTROL_KEY",
columnDefinition="RAW", insertable=false,updatable=false )
})
private CdControl cdControl;
// ...
}
Here I also explicitly pointed RAW type in @JoinColoumn. In EntityManagerProperties hibernate.hbm2ddl.auto = validate
. Hibernate version - 5.1.1 FINAL. But application fails on start on the database validation stage. In stacktrace I see next exception:
Schema-validation: wrong column type encountered in column [CONTROL_KEY] in table [CD_PROPERTY_VALUE]; found [raw (Types#VARBINARY)], but expecting [varchar2(255 char) (Types#VARCHAR)]
In connection with mentioned I have a question: where else I have specify Type to Hibernate pick it up? Or may be I missed something?
It began to work when type in all associations with CdControl was pointed to RAW , not only CdPropertyValue. Shema-validator error message in this situation is confused.