Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » HistoryPolicy: INSERT Error with missing fields(HistoryPolicy: INSERT Error with missing fields)
HistoryPolicy: INSERT Error with missing fields [message #537460] Wed, 02 June 2010 10:16 Go to next message
Wolfgang is currently offline Wolfgang
Messages: 7
Registered: June 2010
Junior Member
Hello,
in my project with several entities HistoryPolicy works for all but one Entity. While dugging I noticed two calls to the history table - the first that is correct is:
Quote:
""INSERT IGNORE INTO organization_hist (id, phone, status, change_time, zipcode, city, country, address, name, tenant, parent, editor, dtype, row_start) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""


the second that fails is:
Quote:
Internal Exception: java.sql.SQLException: Field 'id' doesn't have a default value
Error Code: 1364
Call: INSERT IGNORE INTO organization_hist (zipcode, country, city, change_time, tenant, address, name, row_start) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [76669, DEU, Bad Schönborn, 2010-06-02 16:00:50.812, 4510, Max-Reger-Ring 34, tuakoava, 2010-06-02 16:00:58.109]

I have no clue as to why the second call occurs and why it has a reduced number of fields - any clues? If it helps I can post the corresponding entities, but it's a bit of code.

regards, Wolfgang
Re: HistoryPolicy: INSERT Error with missing fields [message #537702 is a reply to message #537460] Thu, 03 June 2010 08:19 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

That is odd.
Please include the exception stack trace and the mappings for the Entity.


James : Wiki : Book : Blog : Twitter
Re: HistoryPolicy: INSERT Error with missing fields [message #538108 is a reply to message #537460] Sat, 05 June 2010 01:33 Go to previous messageGo to next message
Wolfgang is currently offline Wolfgang
Messages: 7
Registered: June 2010
Junior Member
Hi James,
thx for your support - here some more details. Stack trace:
Quote:

------------- Standard Output ---------------
[EL Info]: 2010-06-05 07:23:11.359--ServerSession(10059989)--EclipseLink, version: Eclipse Persistence Services - 2.0.0.v20091127-r5931
[EL Info]: 2010-06-05 07:23:12.093--ServerSession(10059989)--file:/N:/NetBeansProj ects/Biz2BankPersistency/src/_TisDatabase login successful
[EL Warning]: 2010-06-05 07:23:12.281--UnitOfWork(6867819)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Field 'id' doesn't have a default value
Error Code: 1364
Call: INSERT IGNORE INTO organization_hist (zipcode, country, city, change_time, tenant, address, name, row_start) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [76669, DEU, Bad Schönborn, 2010-06-05 07:23:12.25, 1504, Max-Reger-Ring 34, skkqvnfy, 2010-06-05 07:23:12.265]
Query: InsertObjectQuery(com.tis.biz2bank.server.db.entities.Organi zationalEntity[id=1504])
------------- ---------------- ---------------
Testcase: BasicJpatest(com.tis.biz2bank.server.db.entities.BasicTest): Caused an ERROR
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Field 'id' doesn't have a default value
Error Code: 1364
Call: INSERT IGNORE INTO organization_hist (zipcode, country, city, change_time, tenant, address, name, row_start) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [76669, DEU, Bad Schönborn, 2010-06-05 07:23:12.25, 1504, Max-Reger-Ring 34, skkqvnfy, 2010-06-05 07:23:12.265]
Query: InsertObjectQuery(com.tis.biz2bank.server.db.entities.Organi zationalEntity[id=1504])
javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Field 'id' doesn't have a default value
Error Code: 1364
Call: INSERT IGNORE INTO organization_hist (zipcode, country, city, change_time, tenant, address, name, row_start) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [76669, DEU, Bad Schönborn, 2010-06-05 07:23:12.25, 1504, Max-Reger-Ring 34, skkqvnfy, 2010-06-05 07:23:12.265]
Query: InsertObjectQuery(com.tis.biz2bank.server.db.entities.Organi zationalEntity[id=1504])
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commitInternal(EntityTransactionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commit(EntityTransactionImpl.java:63)
at com.tis.biz2bank.server.db.entities.BasicTest.BasicJpatest(B asicTest.java:50)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Field 'id' doesn't have a default value
Error Code: 1364
Call: INSERT IGNORE INTO organization_hist (zipcode, country, city, change_time, tenant, address, name, row_start) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
bind => [76669, DEU, Bad Schönborn, 2010-06-05 07:23:12.25, 1504, Max-Reger-Ring 34, skkqvnfy, 2010-06-05 07:23:12.265]
Query: InsertObjectQuery(com.tis.biz2bank.server.db.entities.Organi zationalEntity[id=1504])
at org.eclipse.persistence.exceptions.DatabaseException.sqlExce ption(DatabaseException.java:324)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeDirectNoSelect(DatabaseAccessor.java:800)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeNoSelect(DatabaseAccessor.java:866)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.basicExecuteCall(DatabaseAccessor.java:586)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeCall(DatabaseAccessor.java:529)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteCall(AbstractSession.java:914)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.executeCall(DatasourceCallQueryMechanism.java:205)
at org.eclipse.persistence.internal.queries.DatasourceCallQuery Mechanism.insertObject(DatasourceCallQueryMechanism.java:321 )
at org.eclipse.persistence.internal.queries.StatementQueryMecha nism.insertObject(StatementQueryMechanism.java:162)
at org.eclipse.persistence.history.HistoryPolicy.logicalInsert( HistoryPolicy.java:752)
at org.eclipse.persistence.history.HistoryPolicy.postInsert(His toryPolicy.java:711)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.insertObjectForWrite(DatabaseQueryMechanism.java:473)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCom mit(InsertObjectQuery.java:80)
at org.eclipse.persistence.queries.InsertObjectQuery.executeCom mitWithChangeSet(InsertObjectQuery.java:90)
at org.eclipse.persistence.internal.queries.DatabaseQueryMechan ism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:28 6)
at org.eclipse.persistence.queries.WriteObjectQuery.executeData baseQuery(WriteObjectQuery.java:58)
at org.eclipse.persistence.queries.DatabaseQuery.execute(Databa seQuery.java:675)
at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitO fWork(DatabaseQuery.java:589)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery. java:109)
at org.eclipse.persistence.queries.ObjectLevelModifyQuery.execu teInUnitOfWork(ObjectLevelModifyQuery.java:86)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.int ernalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1207)
at org.eclipse.persistence.internal.sessions.AbstractSession.ex ecuteQuery(AbstractSession.java:1167)
at org.eclipse.persistence.internal.sessions.CommitManager.comm itNewObjectsForClassWithChangeSet(CommitManager.java:197)
at org.eclipse.persistence.internal.sessions.CommitManager.comm itAllObjectsWithChangeSet(CommitManager.java:103)
at org.eclipse.persistence.internal.sessions.AbstractSession.wr iteAllObjectsWithChangeSet(AbstractSession.java:3260)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabase(UnitOfWorkImpl.java:1405)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:547)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1510)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUni tOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java: 200)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.com mitAndResume(UnitOfWorkImpl.java:1131)
at org.eclipse.persistence.internal.jpa.transaction.EntityTrans actionImpl.commitInternal(EntityTransactionImpl.java:84)
Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:105 5)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956 )
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:26 48)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedSta tement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedState ment.java:2265)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAcce ssor.executeDirectNoSelect(DatabaseAccessor.java:791)


and here is the hierarchy of involved entities (without getter/setter methods):
Quote:

@MappedSuperclass
public abstract class Biz2BankEntity {
@Id
@Basic(optional = false)
@Column(name = "id", nullable = false)
private Long id;
@Basic(optional = false)
@Column(name = "change_time", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date changeTime;
@JoinColumn(name = "editor", referencedColumnName = "id", nullable = false)
@ManyToOne(optional = false)
private PersonEntity editor;
@JoinColumn(name = "tenant", referencedColumnName = "id", nullable = false)
@ManyToOne(optional = false)
private OrganizationEntity tenant;




Quote:

@Entity
@EntityListeners({UpdateTimeStamp.class})
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "dtype")
@DiscriminatorValue(value = "XXX")
@Table(name = "organization")
public abstract class OrganizationEntity extends Biz2BankEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "phone")
private String phone;
@Column(name = "zipcode")
private String zipcode;
@Column(name = "city")
private String city;
@Column(name = "country")
@Enumerated(EnumType.STRING)
private CountryEnum country;
@Column(name = "address")
private String address;
@Basic(optional = false)
@Column(name = "name")
private String name;
@Column(name = "status")
@Enumerated(EnumType.STRING)
private OrgStatusEnum status;
@JoinColumn(name = "parent", referencedColumnName = "id")
@ManyToOne
private OrganizationEntity parent;
@OneToMany(mappedBy = "legalEntity")
private Collection<PersonEntity> personLegalEntities;
@OneToMany(mappedBy = "roleTarget")
private Collection<PersonRoleOrganizationEntity> personRoleEntities;
@OneToMany(mappedBy = "legalEntity")
private Collection<BankAccountRequestEntity> bankAccountRequestEntities;
@OneToMany(mappedBy = "legalEntity")
private Collection<BankAccountEntity> bankAccountEntities;
@OneToMany(mappedBy = "parent")
private Collection<OrganizationEntity> childrenEntities;
@OneToMany( mappedBy = "tenant")
private Collection<PersonEntity> personTenantEntities;
@OneToMany( mappedBy = "tenant")
private Collection<BankEntity> bankEntities;


the class I am trying to persist is a CompanyEntity:
Quote:

@Entity
@DiscriminatorValue(value = "COM")
public class CompanyEntity extends OrganizationEntity implements Serializable {

private static final long serialVersionUID = 1L;

}

any clues in the given Information?
regards, Wolfgang
Re: HistoryPolicy: INSERT Error with missing fields [message #538110 is a reply to message #538108] Sat, 05 June 2010 01:49 Go to previous messageGo to next message
Wolfgang is currently offline Wolfgang
Messages: 7
Registered: June 2010
Junior Member
Sorry, forgot the code that actually breaks:
Quote:

Biz2BankEntityManager em = Biz2BankEntityManager.getManager();
//create the root user if he doesn't exist
CompanyEntity company = new CompanyEntity();
company.setAddress("adress");
company.setCity("town");
company.setCountry(CountryEnum.DEU);
company.setZipcode("12345");
company.setName(name);
company.setTenant(company);
em.getTransaction().begin();
em.persist(company);
em.getTransaction().commit();



I now found that the problem is the line company.setTenant(company); where I set a reference of the Company to itself. When I remove this it works, but the problem occurs if I add the reference in a later transaction too.

Any clue why history behaves this way? Any suggestion on how to set the reference?

regards, Wolfgang
Re: HistoryPolicy: INSERT Error with missing fields [message #538476 is a reply to message #537460] Mon, 07 June 2010 13:09 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The issue is that EclipseLink is detecting a cycle in the foreign key references of the object. To resolve cyclic constraint dependencies EclipseLink requires to perform a "shallow" insert of the object to avoid violating foreign key constraints.

It looks like this may have issues with EclipseLink history support.
Please log a bug for this and vote for it.

In this case the shallow insert does not seem to be required, as the cycle is only with itself. Please log a bug for this as well.

To avoid the issue, first flush or commit without the reference. Then add the reference in an update.


James : Wiki : Book : Blog : Twitter
Previous Topic:Obtaining Instance of Connection from EM
Next Topic:eclipselink doesn't find my persistence.xml
Goto Forum:
  


Current Time: Sat Jul 26 13:19:13 EDT 2014

Powered by FUDForum. Page generated in 0.02505 seconds