I am creating an application with eclipselink JPA, I am using HistoryPlicy to create historical data. Every thing is working fine, but I am facing a problem with copying blob data to history table.
@Entity
@Customizer(AttachmentHistoryPolicy.class)
@Table(name = "STAFF_ATTACHMENT", catalog = "", schema = "OIA")
public class Attachment implements Serializable {
@Id
private Long id;
@Basic(optional = false)
@NotNull
@Lob
@Column(name = "CONTENTS")
private byte[] contents;
// getters and setters
}
public class AttachmentHistoryPolicy implements DescriptorCustomizer {
@Override
public void customize(ClassDescriptor cd) throws Exception {
HistoryPolicy policy = new HistoryPolicy();
policy.addHistoryTableName("HIST_STAFF_ATTACHMENT");
policy.addStartFieldName("HIST_START_DATE");
policy.addEndFieldName("HIST_END_DATE");
policy.setShouldHandleWrites(true);
//policy.useDatabaseTime();
cd.setHistoryPolicy(policy);
}
}
the row is inserted in the history table, but with empty blob!!!
is there a way to handle this using eclipselink HistoryPolicy ?
EDIT:
following are the sql statements generated by eclipselink
BEGIN INSERT INTO OIA.STAFF_ATTACHMENT (ID, CONTENT_TYPE, CONTENTS, FILE_NAME, FILE_SIZE, OWNER, STAFF_MEMBER) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING CONTENTS INTO ?; END;
SELECT CONTENTS FROM OIA.STAFF_ATTACHMENT WHERE (ID = ?) FOR UPDATE
INSERT INTO HIST_STAFF_ATTACHMENT (ID, CONTENT_TYPE, CONTENTS, FILE_NAME, FILE_SIZE, OWNER, STAFF_MEMBER, HIST_START_DATE) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
SELECT CONTENTS FROM OIA.STAFF_ATTACHMENT WHERE (ID = ?) FOR UPDATE
bind => [1 parameter bound]
note the tow identical statements for select contents for update (the two statements are for STAFF_ATTACHMENT table)
Seems to be an issue with EclipseLink’s support for history in combination of LOB locator support for Oracle platforms.
Please log a bug, but if you are using Oracle 11, then I think LOB now work without a locator, so the workaround is no longer required. Try setting the platform to Oracle11, or just use OraclePlatform which does not use the locator.