hi there, i m currently trying to map 2 table to one class using the hibernate annotation "@SecondaryTable":
Code:
@Entity
@Table(name="entityrevision")
@SecondaryTable(name="productrevision", pkJoinColumns= {
@PrimaryKeyJoinColumn(name="ent_id", referencedColumnName="ent_id"),
@PrimaryKeyJoinColumn(name="rev", referencedColumnName="rev")}
)
public class Product implements Serializable {
private Long _id = null;
private String _title;
private Integer _revisionNumber = null;
private String _imageURL;
@Id
@Column(name="ent_id")
public Long getId() {
return _id;
}
@Id
@Column(name="rev")
public Integer getRevisionNumber() {
return _revisionNumber;
}
@Column(name="title")
public String getTitle() {
return _title;
}
@SuppressWarnings("unused")
private void setTitle(String title) {
this._title = title;
}
@Column(table="productrevision", name="imageurl")
public String getImageURL() {
return _imageURL;
}
@SuppressWarnings("unused")
private void setImageURL(String imageURL) {
_imageURL = imageURL;
}
}
CREATE TABLE entityRevision (
ent_id BIGINT NOT NULL,
rev INTEGER NOT NULL,
title varchar(255) NOT NULL,
PRIMARY KEY (ent_id, rev),
);
CREATE TABLE productRevision (
ent_id BIGINT NOT NULL,
rev INTEGER NOT NULL,
imageUrl varchar(100) NULL,
PRIMARY KEY (ent_id, rev),
FOREIGN KEY (ent_id, rev) REFERENCES entityRevision(ent_id, rev),
);
the problem is that i can load but not persist any created products so that it appears in both tables, i.e. data gets stored to "entityrevision" but not to "productrevision"
hibernate logging for persisting a product is:
Quote:
Hibernate: insert into entityrevision (created_at, title, rev, ent_id) values (?, ?, ?, ?))
this is clearly missing "insert into productrevision ..."
does anybody know what i m doing wrong, all related tutorials i have seen work this way