Hi!
Already posted a similar question on Stackoverflow last week, but since then I’ve managed to change my implementation yet with no success so far.
Situation: I’m trying to persist/merge this entity, newClassification
, of a type I called “Classification
”, which has all the parameters filled in, except for “id” (see code below, please).
This entity has its parameter classicitationType
fully and correctly filled. This last one has its parameter systemType
fully and correctly filled as well.
Tried both with entityManager.persist( newClassification )
and entityManager.merge( newClassification )
with the same result: the insert instruction that is being generated by Hibernate does not reflect all the parameters. E.g.: I get…
c=o.h.SQL, m=logStatement, l=92, msg: insert into plat.classification_system (year, system, id) values (?, ?, ?)
…when I was expecting something like…
c=o.h.SQL, m=logStatement, l=92, msg: insert into plat.classification_system (year, class_type_guid, system, id) values (?, ?, ?, ?)
My database model is as follows (omitted constraint definitions here, but if needed I’ll paste them):
create table classification_system (
id number(19, 0) not null,
year varchar2(255 char) not null,
class_type_guid(48 char ) not null,
system varchar2(255 char) not null,
primary key (id)
)
create table class_type (
guid (48 char) not null,
code varchar2(255 char) not null,
year varchar2(255 char) not null,
system_type_guid varchar2(48 char) not null,
primary key (guid, year)
)
create table system_type (
guid (48 char ) not null,
translation varchar2(255 char) not null,
year varchar2(255 char) not null,
primary key (guid, year)
)
And my Java classes are as follows:
@Entity
@Table("classification_system", indexes = {
@Index(name="CLASS_IDX1",columnList="ID"),
@Index(name="CLASS_IDX2",columnList="ID, SYSTEM"),
@Index(name="CLASS_IDX3",columnList="ID, CLASS_TYPE_GUID, SYSTEM")
})
class Classification extends ClassificationAbstract implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="classSeq")
@SequenceGenerator(name="classSeq", sequenceName="CLASS_SEQ", allocationSize=1)
private Long id;
// couple of constructors...
private String system;
public Classification() {
super();
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getSystem() {
return this.system;
}
public void setSystem(String system) {
this.system = system;
}
}
@MappedSuperclass
public abstract class ClassificationAbstract implements Serializable {
private static final long serialVersionUID = 1L;
@Column(nullable = false)
@NotNull
private String year;
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumns(value = {
@JoinColumn(name = "YEAR", referencedColumnName = "YEAR", insertable = false, updatable = false),
@JoinColumn(name = "CLASS_TYPE_GUID", referencedColumnName = "GUID", insertable = false, updatable = false)
})
private ClassificationType classificationType;
public ClassificationType getClassificationType() {
return classificationType;
}
public void setClassificationType(ClassificationType classificationType) {
this.classificationType = classificationType;
}
}
@Entity
@Table(name="CLASS_TYPE", uniqueConstraints =
@UniqueConstraint(columnNames = {"YEAR", "GUID", "SYSTEM_TYPE_GUID"})
)
public class ClassificationType implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private ClassificationTypePK id;
private String code;
@Column(name = "YEAR", nullable = false)
private String year;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumns({
@JoinColumn(name = "YEAR", referencedColumnName = "YEAR",
insertable = false, updatable = false, nullable = false),
@JoinColumn(name = "SYSTEM_TYPE_GUID", referencedColumnName = "GUID",
insertable = false, updatable = false, nullable = false)
})
private SystemType systemType;
public ClassificationTypePK getId() {
return id;
}
public void setId(ClassificationTypePK id) {
this.id = id;
}
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
public String getSystemType() {
return this.systemType;
}
public void setSystemType(String systemType) {
this.systemType = systemType;
}
}
@Embeddable
public class ClassificationTypePK implements Serializable {
private static final long serialVersionUID = 1L;
private String guid;
private String year;
//getters + setters + hashCode + equals implementations...
}
@Entity
@Table(name="SYSTEM_TYPE", uniqueConstraints =
@UniqueConstraint(columnNames = {"YEAR", "GUID"})
)
public class SystemType implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private SystemTypePk id;
private String translation;
public SystemTypePk getId() {
return id;
}
public void setId(SystemTypePk id) {
this.id = id;
}
public String getTranslation() {
return translation;
}
public void setTranslation(String translation) {
this.translation = translation;
}
//hashCode + equals implementations...
}
@Embeddable
public class SystemTypePL implements Serializable {
private static final long serialVersionUID = 1L;
private String guid;
private String year;
//getters + setters + hashCode + equals implementations...
}
I’m presently working on a Oracle XE database with Java EE7 + Hibernate 5.0.9 (final).
Am I leaving something out? Or am I doing something that it is just not right?