classcastexception « Data Type « JPA Q&A

1. ClassCastException when usign HQL

See the following mapping

public class SomeClass {

    private Integer someField;

When i call the following query
select someField, count(*) from SomeClass inner join OtherClass... group by ...
And i proccess the ...

2. java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object

Im running following query it will display error message. How to solve this error.

        List<?> companyList ...

3. Hibernate -> ArrayList cannot be cast to Set

I have a Java EE application and I use Hibernate. The domain objects, I changed the List / ArrayList to Set / HashSet, because it is better to use Sets. But in ...

4. Hibernate/HQL/JPQL: what's wrong with a CASE WHEN ... THEN NULL ELSE ... END (ClassCastException)?

I have the following JPQL/HQL snippet in a SELECT

 MAX(CASE WHEN scf.finalScore = 20 OR scf.finalScore = 0 THEN NULL ELSE scf.finalScore END) AS hi,
 MIN(CASE WHEN scf.finalScore = 20 OR ...

5. java.lang.ClassCastException: java.lang.Integer cannot be cast

When i click on login, it checks the DB if there is a value matching then i get this error, else it does print me null.

public Login authenticate(Login login) {

6. HQL IN operator, Array of Enums ClassCastException

Here is my stripped down class and enum.

class A
    @Enumerated (value = EnumType.STRING)
    AType type;

enum AType
if I run
query = FROM ...

7. java.lang.ClassCastException: org.hibernate.hql.ast.tree.SqlNode cannot be cast to org.hibernate.hql.ast.tree.FromReferenceNode

Im trying to update a record with a HQL query but im getting a cast exception. If anyone could help me out i would really appreciate it. I have checked the internet for ...

8. ClassCastException HashMap not a PersistentCollection

Hi, I'm trying to persist a map but a ClassCastException occurs when trying to count the items (select count suing a native query). I use the 3.3.0.SP1 release of hibernate core. The mapping file:

9. ClassCastException with Enumerated CollectionOfElements

I have the following mapping @Entity @Table(name = "av_contribution") public class Contribution { ..... @CollectionOfElements(targetElement = BoardKind.class) @Enumerated(EnumType.STRING) @JoinTable(name = "av_contrib_boardkind", joinColumns = @JoinColumn(name = "cid")) Set boardKinds = new HashSet(); ..... When I do a merge of this entity I get: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum at org.hibernate.type.EnumType.nullSafeSet( at org.hibernate.type.CustomType.nullSafeSet( at org.hibernate.persister.collection.AbstractCollectionPersister.writeElement( at org.hibernate.persister.collection.AbstractCollectionPersister.insertRows( at org.hibernate.action.CollectionUpdateAction.execute( Using hibernate ...

10. ClassCastException: QueryKey cannot be cast to CacheKey

I get a ClassCastException when I try to do the following: Map cacheEntries = sessionFactory.getStatistics().getSecondLevelCacheStatistics(regionName).getEntries(); Any pointers to what could be wrong here? I am using: Java 1.6 Hibernate 3.5.3 GWT 2.0 I get the same exception when I use EhCache as well. However, I was expecting Hashtable cache to work. My second level cache config is

17. java.lang.ClassCastException: java.lang.String while saving

Hi , I am getting ClassCastException whenever i try to save one of my Object. I have checked my Database tables , Classes Definition as well as mapping definition all have similar "types" for all the properties/columns still it is giving this exception . I checked the log created at server it is also generating the right queries and binding with ...

18. ClassCastException: HqlToken cannot be cast to antlr.Token

Hi All, I am getting ClassCastException. Here are some details. We have two applications. Both applications using the hibernate and same version and jars added in their jar libs folder. The main application loads the 2nd application using java class loader and loads all the jars inside the .jar file lib foler. Once both application loaded and database schema created by ...