Bug 420 : SQLException with CascadeType.REMOVE
Priority 
High
Reported Version 
 
Logged By 
Mikael
Status 
Fixed
Fixed Version 
3.x
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
30/08/2012
Updated 
30/08/2012
Type 
Bug
 
Attachments 
No attachments

See discussion about this bug here:
https://groups.google.com/forum/?fromgroups=&pli=1#!topic/ebean/K4xZZFvYoMk

I've got a problem deleting a "parent object" using CascadeType.REMOVE.
The parent and the child objects are of the same type (ResourceFile).
I'm running Ebean 2.7.3 with Play Framework 2.0.2.

The class:

@Entity
@Table(name = "ResourceFile")
public class ResourceFile extends ... {
private static final long serialVersionUID = 1L;

@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "parentResourceFileId", nullable = true)
private ResourceFile parent;

...

@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY,
mappedBy = "parent", orphanRemoval = true)
private Set alternatives = new HashSet<>();

...

public ResourceFile getParent() {
return parent;
}

public void setParent(ResourceFile parent) {
this.parent = parent;
}

public Set getAlternatives() {
return alternatives;
}

public void setAlternatives(Set alternatives) {
this.alternatives = alternatives;
}
}

A Maven project for the test case can be downloaded here:
http://test.incompleteopus.net/ebean-bug-cascade-remove.zip

In the test case I create one parent object and two children. Then I try to delete the parent object, which should delete the child objects as well due to CascadeType.REMOVE.

I was using Ebean 2.7.3 in my Play Framework-based project, but I confirmed the same error using the standalone test case in 2.7.7.

Here's the transaction log for the error:

txn[1003], 21:20:40.166, insert into ResourceFile (id, name, parentResourceFileId) values (?,?,?)
txn[1003], 21:20:40.168, Binding Insert [ResourceFile] set[id=01080031-e3ed-463f-9f7d-3d9759b1a13e, name=parentFile1, parentResourceFileId=null, ]
txn[1003], 21:20:40.169, Inserted [ResourceFile] [01080031-e3ed-463f-9f7d-3d9759b1a13e]
txn[1004], 21:20:40.176, insert into ResourceFile (id, name, parentResourceFileId) values (?,?,?)
txn[1004], 21:20:40.176, Binding Insert [ResourceFile] set[id=bc494540-5caf-4c83-9425-19bee351b84a, name=childFile1, parentResourceFileId=01080031-e3ed-463f-9f7d-3d9759b1a13e, ]
txn[1004], 21:20:40.176, Inserted [ResourceFile] [bc494540-5caf-4c83-9425-19bee351b84a]
txn[1005], 21:20:40.177, insert into ResourceFile (id, name, parentResourceFileId) values (?,?,?)
txn[1005], 21:20:40.177, Binding Insert [ResourceFile] set[id=0cd05a7c-9f54-45b4-9013-ddc5baf9f2a3, name=childFile2, parentResourceFileId=01080031-e3ed-463f-9f7d-3d9759b1a13e, ]
txn[1005], 21:20:40.177, Inserted [ResourceFile] [0cd05a7c-9f54-45b4-9013-ddc5baf9f2a3]
txn[1006], 21:20:40.242, select t0.id c0 from ResourceFile t0 where parentResourceFileId=?
txn[1006], 21:20:40.246, FindIds exeMicros[3807] rows[2] type[ResourceFile] predicates[parentResourceFileId=? ] bind[01080031-e3ed-463f-9f7d-3d9759b1a13e, ]
txn[1006], 21:20:40.262, select t0.id c0 from ResourceFile t0 where (parentResourceFileId) in (?,?)
txn[1006], 21:20:40.264, FindIds exeMicros[2052] rows[0] type[ResourceFile] predicates[(parentResourceFileId) in (?,?) ] bind[bc494540-5caf-4c83-9425-19bee351b84a, 0cd05a7c-9f54-45b4-9013-ddc5baf9f2a3, ]
txn[1006], 21:20:40.265, select t0.id c0 from ResourceFile t0 where (parentResourceFileId) in (?)
txn[1006], 21:20:40.280, ERROR executing query: bindLog[] error[Parameter "#1" is not set; SQL statement:\n select t0.id c0 \n from ResourceFile t0 \n where (parentResourceFileId) in (?) [90012-168]]
txn[1006], 21:20:40.293, Rollback

Here's the stack trace:

Query threw SQLException:No value specified for parameter 1
[error] Bind values:[]
[error] Query was:
[error] select t0.id c0
[error] from ResourceFile t0
[error] where (parentResourceFileId) in (?)
[error]
[error] at com.avaje.ebeaninternal.server.query.CQuery.createPersistenceException(CQuery.java:849)
[error] at com.avaje.ebeaninternal.server.query.CQueryEngine.findIds(CQueryEngine.java:100)
[error] at com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine.findIds(DefaultOrmQueryEngine.java:63)
[error] at com.avaje.ebeaninternal.server.core.OrmQueryRequest.findIds(OrmQueryRequest.java:318)
[error] at com.avaje.ebeaninternal.server.core.DefaultServer.findIdsWithCopy(DefaultServer.java:1330)
[error] at com.avaje.ebeaninternal.server.core.DefaultServer.findIds(DefaultServer.java:1322)
[error] at com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany.findIdsByParentIdList(BeanPropertyAssocMany.java:283)
[error] at com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany.findIdsByParentId(BeanPropertyAssocMany.java:240)
[error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:574)
[error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:575)
[error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.deleteManyDetails(DefaultPersister.java:1189)
[error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.deleteAssocMany(DefaultPersister.java:1156)
[error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:643)
[error] at com.avaje.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:464)
[error] at com.avaje.ebeaninternal.server.core.DefaultServer.delete(DefaultServer.java:1831)
[error] at com.avaje.ebeaninternal.server.core.DefaultServer.delete(DefaultServer.java:1821)
[error] at com.avaje.ebean.Ebean.delete(Ebean.java:678)
[error] at play.db.ebean.Model.delete(Model.java:142)
[error] ...
[error] Caused by: java.sql.SQLException: No value specified for parameter 1
[error] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
[error] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
[error] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
[error] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
[error] at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2595)
[error] at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2571)
[error] at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2497)
[error] at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2251)
[error] at com.jolbox.bonecp.PreparedStatementHandle.executeQuery(PreparedStatementHandle.java:172)
[error] at com.avaje.ebeaninternal.server.query.CQueryFetchIds.findIds(CQueryFetchIds.java:187)
[error] at com.avaje.ebeaninternal.server.query.CQueryEngine.findIds(CQueryEngine.java:85)
[error] ... 88 more

 
Daniel 25 Nov 02:48
Any updates?

I've seen this discussed in various places online and was just wondering if there's any news on this?

Lev 29 Nov 14:26
Same here

We're facing the same issue.
This is serious problem in case of single table inheritance as well.
Please fix this bug as soon as possible.
Thanks.

woResponse

Upload a file