Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » History Policy(History policy is not working, the log shows that "Internal Exception: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "PK"; SQL statement:")
History Policy [message #1784565] Thu, 29 March 2018 11:30 Go to next message
prabhanjan kumar is currently offline prabhanjan kumarFriend
Messages: 1
Registered: March 2018
Junior Member
Here is my entity setup:

@Entity
@Table(name = "ENTITY_TBL")
@Customizer(EntityCustomizer.class)
public class EntityCls implements Serializable {

@Id
@GeneratedValue
@Column(name = "TBL_ID")
private Long tblId;

@Column(name = "TBL_NAME", nullable = false)
@Size(min = 1, max = 255, message = "{name.size}")
@NotNull(message = "{name.required}")
private String tblName;

......
getters, setters


}


@Entity
@Table(name = "ENTITY_HIST")
public class EntityHistory implements Serializable {

@Id
@GeneratedValue
private Long pk;

@Column(name = "TBL_ID")
private Long tblId;

@Column(name = "TBL_NAME")
private String tblName;

@Column(name = "START")
@Temporal(TemporalType.TIMESTAMP)
private Date start;

@Column(name = "END")
@Temporal(TemporalType.TIMESTAMP)
private Date end;

......
getters, setters

}


public class EntityCustomizer implements DescriptorCustomizer {

@Override
public void customize(ClassDescriptor cd) throws Exception {
HistoryPolicy policy = new HistoryPolicy();
policy.addStartFieldName("START");
policy.addEndFieldName("END");
policy.addHistoryTableName("ENTITY_HIST");
policy.setShouldHandleWrites(true);
cd.setHistoryPolicy(policy);
}

}

I can see insert statements generated in the log for ENTITY_TBL and ENTITY_HIST tables, but while inserting in history table ENTITY_HIST, the primary key is null and hence the exception is thrown.

"Internal Exception: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "PK"; SQL statement:"

I have also tried other sequence strategy like sequence strategy but still not working as expected. Any help is appreciated.

Thanks,
Prabhanjan
Re: History Policy [message #1784830 is a reply to message #1784565] Wed, 04 April 2018 14:17 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The history policy to use the ENTITY_HIST for the ENTITY_TBL history is outside of JPA. Your EntityHistory entity is adding in the ID field that is not used for history entries causing your problems - if you wish to map it as an entity, you are going to need to use a compound identifier composed of existing fields, like "TBL_ID" and "START" and possibly "END" to uniquely identify rows.
Previous Topic:Data too long for column error but it should fit
Next Topic:Oracle 12c support
Goto Forum:
  


Current Time: Fri Apr 26 12:36:28 GMT 2024

Powered by FUDForum. Page generated in 0.03005 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top