I have been facing the below class-cast-exception in hibernate in our test environments on and off.
Any ideas anyone how to resolve this?? thx much.
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.Set
at org.hibernate.type.SetType.wrap(SetType.java:58)
at org.hibernate.event.internal.WrapVisitor.processArrayOrNewCollection(WrapVisitor.java:108)
using:
java 1.8. hibernate 4.3.11 MS SQL Server
I have looked some other of threads, but are seems different case than my mine.
08:29:15,825 ERROR jobLauncherTaskExecutor-4 AbstractStep:225 - Encountered an error executing step abcde in job dailyfeed
**java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.Set
at org.hibernate.type.SetType.wrap(SetType.java:58)
at** org.hibernate.event.internal.WrapVisitor.processArrayOrNewCollection(WrapVisitor.java:108)
at org.hibernate.event.internal.WrapVisitor.processCollection(WrapVisitor.java:73)
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:121)
at org.hibernate.event.internal.WrapVisitor.processValue(WrapVisitor.java:125)
at org.hibernate.event.internal.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:76)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.wrapCollections(DefaultFlushEntityEventListener.java:220)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:157)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:231)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:102)
at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:61)
at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1227)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1293)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at org.springframework.orm.hibernate4.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:904)
at org.springframework.orm.hibernate4.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:894)
at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:341)
at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:309)
at org.springframework.orm.hibernate4.HibernateTemplate.findByNamedParam(HibernateTemplate.java:894)
at org.springframework.orm.hibernate4.HibernateTemplate.findByNamedParam(HibernateTemplate.java:884)
at net.A.B.stage.dao.BillingPeriodHibernateDao.billingPeriodsById(BillingPeriodHibernateDao.java:29)
at net.A.B.stage.service.BillingPeriodSpringService.billingPeriodsById(BillingPeriodSpringService.java:31)
From the above stack trace and when trying to analyze the above hibernate source code, it seems for every get-call to a table, hibernate always tries to flush out any pending changes to the table, in the current session. As part of this trace, it seems is working with collections of data and seems when trying typecast, is actually finding a Boolean in the internal code at SetType/WrapVisitor.
But I see in my code, there is no other parallel get/update call to this table.
and when trying recreate/debug, haven't been able to recreate the error.
The below are the java/mapping code. No other queries are getting run to modify this table at the same time. As such the application has only this get queries to this table.
--Java Code--
@Override
public List<BillingOrg> getBillingOrg(Integer operativeOrgId) {
DetachedCriteria crits = DetachedCriteria.forClass(BillingOrg.class);
crits.add(Restrictions.eq("operativeId", operativeOrgId.longValue()));
return (List<BillingOrg>) getHibernateTemplate().findByCriteria(crits);
}
BillingBoard.java
public class BillingPeriod implements Serializable {
private static final long serialVersionUID = 1L;
private BillingPeriodKey id;
private String billingPeriodName;
private String billingSchemeName;
private String billingSchemeType;
private Date billingPeriodStartDate;
private Date billingPeriodEndDate;
public BillingPeriodKey getId() {
return id;
}
public void setId(BillingPeriodKey id) {
this.id = id;
}
BillingPeriodKey.java
public class BillingPeriodKey implements Serializable {
private static final long serialVersionUID = 1L;
private int billingPeriodId;
private int scheme_id;
public int getBillingPeriodId() {
return billingPeriodId;
}
public void setBillingPeriodId(int billingPeriodId) {
this.billingPeriodId = billingPeriodId;
}
--Mapping file--
<class name="net.A.B.stage.model.BillingPeriod" table="billing_period">
<composite-id name="id"
class="net.A.B.stage.model.BillingPeriodKey">
<key-property name="billingPeriodId">
<column name="billing_period_id" sql-type="INT" />
</key-property>
<key-property name="scheme_id">
<column name="billing_scheme_id" sql-type="INT" />
</key-property>
</composite-id>
<property name="billingPeriodName" column="billing_period_name" />
<property name="billingSchemeName" column="billing_scheme_name" />
<property name="billingSchemeType" column="billing_scheme_type" />
<property name="billingPeriodStartDate" column="billing_period_start_date" />
<property name="billingPeriodEndDate" column="billing_period_end_date" />
</class>
Updates from more testing/research--
Forgot to mention earlier, the application is running on tomcat7.
Still not able to recreate this issue from local against our dev/test databases. This issue is happening now more frequently on the test and prod tomcat servers. This select-issue has been happening just for this one specific table. We have about 50 tables, the application/batch-process does inserts/updates/selects against them. We have bounced the application and restarted the server(test/prod) multiple times. I can only see something wrong, with the tomcat instance or hibernate-cache or somewhere, somehow having a bad copy of this table/entity is being cached. What could be the problem with ?? or what could be done more, to have test/prod tomcat/hibernate get working good with this table/entity.
To share more details about the application, the application/ spring-batch-process loads this table/tables as part of the batch process, and at a point in the batch, when selects are run against this table, the issue starts to happen on the test/prod servers (getting more frequently now).