Cast exception on Delete

14 views
Skip to first unread message

Thibault Meyer

unread,
Feb 7, 2017, 1:25:38 PM2/7/17
to Ebean ORM
Hi,

I try to delete an entry, but I get this error (Ebean 10.1.3) : io.ebeaninternal.server.expression.DefaultExpressionList cannot be cast to io.ebean.Query



final ContractModel contract = ContractModel.find
           
.query()
           
.where()
           
.eq("uid", UUID.fromString("07a89b96-781a-44d8-bc1f-30429b0eb465"))
           
.findUnique();
        contract
.delete();



[debug] io.ebean.SQL - txn[1001] select t0.id, t0.uid, t0.created_at, t0.last_update, t0.name, t0.slug, t1.id, t1.uid, t1.created_at, t1.last_update, t1.date_start, t1.date_end, t1.is_payout_enabled, t1.is_topup_enabled, t1.is_invoice_enabled, t1.is_int_store_enabled, t1.is_ext_store_enabled, t1.is_recycle_reg_token_enabled, t1.currency, t1.topup_min_amount, t1.topup_max_amount, t1.wallet_settings, t1.paypal_settings, t1.payzen_settings, t1.contract_id, t2.id, t2.uid, t2.created_at, t2.last_update, t2.primary_color, t2.secondary_color, t2.title_1, t2.title_2, t2.description, t2.website, t2.background_url, t2.contract_id from contract t0 join contract_settings t1 on t1.contract_id = t0.id  join contract_store_settings t2 on t2.contract_id = t0.id  where t0.uid = ?
[debug] io.ebean.SQL - txn[1002] select t0.id, t0.uid, t0.created_at, t0.last_update, t0.name, t0.client, t0.secret, t0.sec_policies, t0.business_actor_id from api_key t0 where t0.client like ? escape''  and t0.secret like ? escape''
[debug] io.ebean.SQL - txn[1003] delete from contract_settings where id=?
[debug] io.ebean.SQL - txn[1003] delete from contract_store_settings where id=?
[debug] io.ebean.SQL - txn[1003] select t0.id from nfc_medium t0 where contract_id=?
[error] application - Fatal error on DELETE /api/admin/contract/a8587dbb-264d-4189-9693-51fc7de136d6 called by 127.0.0.1 [UserID: -]
java
.util.concurrent.CompletionException: java.lang.ClassCastException: io.ebeaninternal.server.expression.DefaultExpressionList cannot be cast to io.ebean.Query
 at java
.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
 at java
.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
 at java
.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
 at java
.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
 at java
.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
 at java
.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
 at scala
.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:21)
 at scala
.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:18)
 at scala
.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
 at scala
.concurrent.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:63)
Caused by: java.lang.ClassCastException: io.ebeaninternal.server.expression.DefaultExpressionList cannot be cast to io.ebean.Query
 at io
.ebeaninternal.server.deploy.BeanPropertyAssocOne.findIdsByParentIdList(BeanPropertyAssocOne.java:267)
 at io
.ebeaninternal.server.deploy.BeanPropertyAssocOne.findIdsByParentId(BeanPropertyAssocOne.java:233)
 at io
.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:645)
 at io
.ebeaninternal.server.persist.DefaultPersister.deleteChildrenById(DefaultPersister.java:1300)
 at io
.ebeaninternal.server.persist.DefaultPersister.deleteManyDetails(DefaultPersister.java:1276)
 at io
.ebeaninternal.server.persist.DefaultPersister.deleteAssocMany(DefaultPersister.java:1242)
 at io
.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:749)
 at io
.ebeaninternal.server.persist.DefaultPersister.deleteRequest(DefaultPersister.java:542)
 at io
.ebeaninternal.server.persist.DefaultPersister.deleteRequest(DefaultPersister.java:522)
 at io
.ebeaninternal.server.persist.DefaultPersister.delete(DefaultPersister.java:514)

Rob Bygrave

unread,
Feb 8, 2017, 5:09:49 AM2/8/17
to ebean@googlegroups
Ok thanks. I'll have to look and see how to reproduce.

--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Thibault Meyer

unread,
Feb 8, 2017, 8:08:03 AM2/8/17
to Ebean ORM
Hi Rob,

Its something related to Foreign Key "loop". Model A use Model B, Model B use Model C and Model C use Model A.

When I delete an entry of type "A" (Contract), Ebean try to follow cascade and finally try to delete something already deleted.

I have resolved issue by changing variable declaration order and removing some extra cascade.

Maybe Ebean could implement something to avoir this kind of issue, or try to determine order when running "cascade" (not just using the variable declaration order)



Model A "Contract"

@OneToMany(mappedBy = "contract", cascade = CascadeType.REMOVE)
@OrderBy("id ASC")
private List<NfcMediumModel> nfcMediums;

@OneToMany(mappedBy = "contract", cascade = CascadeType.REMOVE)
@OrderBy("id ASC")
private List<NfcMediumSlotModel> nfcMediumSlots;



Model B "NFC Slot"

@ManyToOne(targetEntity = ContractModel.class)
@JoinColumn(name = "contract_id", nullable = false)
private ContractModel contract;

@OneToOne
@JoinColumn(name = "nfc_medium_id", cascade = CascadeType.REMOVE)
private NfcMediumModel nfcMedium;




Model C "NFC Tag"

@ManyToOne(targetEntity = ContractModel.class)
@JoinColumn(name = "contract_id", nullable = false)
private ContractModel contract;

@OneToOne(mappedBy = "nfcMedium")
private NfcMediumSlotModel nfcMediumSlot;
Reply all
Reply to author
Forward
0 new messages