0

I am using service in CUBA-FRAMEWORK to do some data manipulation and getting the following error:

ClassCastException: java.util.Date cannot be cast to com.company.gms.entity.ProductionPlanResource

the error is originated in the following line of code:

matReqDate = DateUtils.addDays((Date)planQuery.getFirstResult().getStartDate(), daysOffset);
                                            }

additional codes around :

    Date reqShipDate = soline.getRequiredShipDate();
                                                Date matReqDate;
                                                TypedQuery<ProductionPlanResource> planQuery = persistence.getEntityManager()
                                                        .createQuery("select MIN(e.startDate) from mydb$ProductionPlanResource e " +
                                                                " where e.productionPlan.salesOrder.id = ?1 AND e.article.id = ?2", ProductionPlanResource.class);
                                                        planQuery.setParameter(1, soline.getSalesOrder().getId()).setParameter(2, article.getId());

                                                if (planQuery.getResultList().size() > 0) {

                                                    matReqDate = DateUtils.addDays((Date)planQuery.getFirstResult().getStartDate(), daysOffset);
                                                }

I tried this, but didn't help

java.sql.Date startDate = (java.sql.Date)planQuery.getFirstResult().getStartDate();

Thanks for helping.

1
  • What is the type of planQuery.getFirstResult().getStartDate() ? Is it a java.util.Date ? or a java.sql.Date ?. Can you print getClass().getName() and see what is output ? Commented Aug 30, 2016 at 7:52

3 Answers 3

1

Your TypedQuery is expected to return a ProductionPlanResource but looking at the query itself, it gives back MIN(e.startDate) which seems to be a date instead of a ProductionPlanResource.

Sign up to request clarification or add additional context in comments.

Comments

1

The exception tells You that there is a Date which is cast to ProductionPlanResource. That is the problem.

TypedQuery<ProductionPlanResource> planQuery =  ...
...select MIN(e.startDate) from ...

The result is a Date and the TypedQuery is for type ProductionPlanResource.

Try change to:

TypedQuery<Date> planQuery

Comments

0

You could try to .getTime() and then convert, since long value is read by both, java and sql date.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.