Can you help me to correct this function. I have been having anomaly since I migrated from jee javax to jakartaee. It's work well on jee, but not on JakartaEE
public <T extends GenericInputTimesheet> List<T> findWhereItemToto(Class<T> entityClass, Integer value
)
Here is my simplified Jakarta JPA data model. (I’m not including the getters/setters here for readability)
@MappedSuperclass
public abstract class GenericInputTimesheet<T extends GenericTimesheetItem> implements Serializable {
@Id
private long id;
@NotNull
@ManyToOne
private T item;
}
@MappedSuperclass
public class GenericTimesheetItem implements Serializable {
@Id
private long id;
private Integer toto;
}
@Entity
public class InputTimesheetMandat extends GenericInputTimesheet<Mandat> {
}
@Entity
public class Mandat extends GenericTimesheetItem {
}
Then I have this function
public <T extends GenericInputTimesheet> List<T> findWhereItemToto(Class<T> entityClass, Integer value) {
return entityManager.createQuery("Select e From " + entityClass.getSimpleName() + " e Where e.item.toto=:toto", entityClass)
.setParameter("toto", value)
.getResultList();
}
My launcher :
public void displayToto(Integer value) {
try {
List<InputTimesheetMandat> inputs = pocService.findWhereItemToto(InputTimesheetMandat.class, value);
System.out.println(inputs.size() + " InputTimesheetMandat Toto = " + value + " founds");
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
I catch this exception :
java.lang.ClassCastException: class org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl cannot be cast to class org.hibernate.metamodel.model.domain.EntityDomainType (org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl and org.hibernate.metamodel.model.domain.EntityDomainType are in unnamed module of loader '[email protected]' @304f8087)
I fix the probleme