I am having problems in Hibernate when searching with Criteria and adding an ID Restriction. Oracle throws an ArrayIndexOutOfBoundsException, which is eventually thrown by Hibernate as a GenericJDBCException.
My finder method works fine when adding normal (non-id) restrictions. However, when I try to add a restriction for an ID field, it fails.
However, I have found that sometimes it works! The persisted class is defined below. If you try to comment either of the four attributes (createdDate, chagnedDate, changedUserId, recordVersion) the finder method works!
I cannot seem to find a pattern to this. I do not know if it matters, but I am mapping this object to a view to a table across a database link. This has not had an effect up to now.
Any ideas or help would be appreciated!
I am using JDK1.5, Hibernate 3.2.2.
robin
Here is the persisted class:
Code:
package com.mycompany.debpt.proj.integration.cds.domain;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Version;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.codehaus.xfire.aegis.type.java5.XmlType;
import org.hibernate.annotations.Type;
@Entity
@Table(name="BIG_VIEW")
public class IndustryGroup {
private static final long serialVersionUID = 1L;
private long id;
private String name;
// protected Boolean logicallyDeleted = false;
// protected String createdUserId;
// Comment out any one of the next four attributes (along
// with the corresponding getter and setter) and idEq() works.
protected Date createdDate;
protected Date changedDate;
protected String changedUserId;
protected Long recordVersion = 0L;
@Id
@Column(name="BIG_ID")
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(name="NAME")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column
public Date getChangedDate() {
return changedDate;
}
public void setChangedDate(Date changedDate) {
this.changedDate = changedDate;
}
@Column
public String getChangedUserId() {
return changedUserId;
}
public void setChangedUserId(String changedUserId) {
this.changedUserId = changedUserId;
}
@Column
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
@Column
public String getCreatedUserId() {
return createdUserId;
}
public void setCreatedUserId(String createdUserId) {
this.createdUserId = createdUserId;
}
// @Column(length = 1)
// @Type(type = "yes_no")
// public Boolean isLogicallyDeleted() {
// return logicallyDeleted;
// }
// public void setLogicallyDeleted(Boolean logicallyDeleted) {
// this.logicallyDeleted = logicallyDeleted;
// }
@Column
public Long getRecordVersion() {
return recordVersion;
}
public void setRecordVersion(Long recordVersion) {
this.recordVersion = recordVersion;
}
}
The table which I am storing this object in:Code:
create table big
(
BIG_ID number(4) not null,
name varchar2(255 byte) not null,
CREATED_USER_ID varchar2(50 byte),
CREATED_DATE timestamp(6),
CHANGED_USER_ID varchar2(50 byte),
CHANGED_DATE timestamp(6),
LOGICALLY_DELETED char(1 byte),
RECORD_VERSION number(19) not null
)
This is my finder method which only fails when searching with an ID restriction:Code:
public List<IndustryGroupSearchResultsDto> findIndustryGroups(IndustryGroupSearchFormDto searchFormDto) {
Session session = SessionFactoryUtils.getSession(sessionFactory, true);
Criteria criteria = session.createCriteria(IndustryGroup.class);
criteria.addOrder(Order.asc("name"));
if (searchFormDto.getName() != null) {
criteria.add(Restrictions.like("name", searchFormDto.getName(), MatchMode.START).ignoreCase());
}
if (searchFormDto.getCode() != null) {
// TODO: Currently this is not working ....
criteria.add(Restrictions.idEq(searchFormDto.getCode()));
}
List<IndustryGroupSearchResultsDto> results = new ArrayList<IndustryGroupSearchResultsDto>();
List<IndustryGroup> found = criteria.list();
for (IndustryGroup groupFound : found) {
IndustryGroupSearchResultsDto dto = new IndustryGroupSearchResultsDto();
dto.setCode(Long.toString(groupFound.getId()));
dto.setName(groupFound.getName());
results.add(dto);
}
return results;
}
The exception thrown is:Code:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2214)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.mycompany.dept.proj.referencedata.service.ReferenceDataServiceImpl.findIndustryGroups(ReferenceDataServiceImpl.java:376)
at com.mycompany.dept.proj.referencedata.service.ReferenceDataServiceTest.testFindIndustryGroupsByCode(ReferenceDataServiceTest.java:297)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.ArrayIndexOutOfBoundsException: 7
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:62)
at com.mchange.v2.c3p0.impl.NewPooledConnection.handleThrowable(NewPooledConnection.java:369)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getTimestamp(NewProxyResultSet.java:3408)
at org.hibernate.type.TimestampType.get(TimestampType.java:30)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2092)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
at org.hibernate.loader.Loader.getRow(Loader.java:1197)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
... 23 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 7
at oracle.sql.TIMESTAMP.toTimestamp(TIMESTAMP.java:300)
at oracle.jdbc.driver.OracleStatement.getTimestampValue(OracleStatement.java:5084)
at oracle.jdbc.driver.OracleResultSetImpl.getTimestamp(OracleResultSetImpl.java:689)
at oracle.jdbc.driver.OracleResultSet.getTimestamp(OracleResultSet.java:1692)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getTimestamp(NewProxyResultSet.java:3394)
... 35 more