Hi I have a problem that I can't solve on my own. I have a war file packaged in ear and running on glassfish 3.0.1 with hibernate 3.5 as JPA provider. I compile it with maven and deploy it with idea or manually. Every other time I get a cast exception in my DAOs:
java.lang.ClassCastException: com.myproject.domain.entity.User cannot be cast to
com.myproject.domain.entity.User
Other times it works perfectly fine. There is no pattern in this behaviour. Could someone shine some light on what is happening here?
Example method where the exception was thrown at com.myproject.domain.dao.UserDAOImpl.checkUserSessionValid(UserDAOImpl.java:195)
public User checkUserSessionValid(String sessionId) {
User user = null;
EntityManager em = provider.entityManager();
try {
em.getTransaction().begin();
//Query q = em.createQuery("SELECT u FROM User u WHERE u.session.sessionId = :sessionId"); makes no difference :/
Query q = em.createQuery("SELECT u FROM User u WHERE u.session.sessionId = :sessionId",User.class);
q.setParameter("sessionId", sessionId);
user = (User) q.getSingleResult();
em.getTransaction().commit();
} catch (NoResultException ignored) {
} finally {
em.close();
}
return user;
}
My libraries
[INFO] +- org.apache.geronimo.specs:geronimo-jpa_2.0_spec:jar:1.0:provided
[INFO] +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- org.hibernate:hibernate-annotations:jar:3.5.1-Final:compile
[INFO] | +- org.hibernate:hibernate-core:jar:3.5.1-Final:compile
[INFO] | | +- antlr:antlr:jar:2.7.6:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | | \- javax.transaction:jta:jar:1.1:provided (scope managed from compile)
[INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.5.2:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.1-Final:compile
[INFO] | +- cglib:cglib:jar:2.2:compile
[INFO] | | \- asm:asm:jar:3.1:compile
[INFO] | \- javassist:javassist:jar:3.9.0.GA:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.1.0.Final:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.5.2:test
[INFO] +- mysql:mysql-connector-java:jar:5.1.13:test
[INFO] +- org.hsqldb:hsqldb:jar:2.0.0:test