您好我在Struts2 hibernate应用程序中一直收到此错误。以下是此错误的堆栈跟踪
SEVERE: Could not instantiate collection persister org.hibernate.persister.collection.BasicCollectionPersister
org.hibernate.MappingException: Could not instantiate collection persister org.hibernate.persister.collection.BasicCollectionPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:242)
at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:201)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:430)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at projectBroomKetuActionDataItrfc.dto.HibernateUtility.getSessionFactory(HibernateUtility.java:19)
at projectBroomKetuActionDataItrfc.dto.DatabaseInteractionInterface.checkDataDuplication(DatabaseInteractionInterface.java:60)
at projectBroomKetuAction.SignUpActionClass.validate(SignUpActionClass.java:462)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:251)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.persister.collection.AbstractCollectionPersister.generateSelectSizeString(AbstractCollectionPersister.java:1020)
at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:528)
at org.hibernate.persister.collection.BasicCollectionPersister.<init>(BasicCollectionPersister.java:77)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:231)
... 66 more
下面是hibernat.cfg.xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/b#%^^DB</property>
<property name="connection.username">****</property>
<property name="connection.password">******</property>
<!-- JDBC connection pool (use the built-in) -->
<!--
<property name="connection.pool_size">10</property> --> <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> <property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">15</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">30</property>
<!-- Connection testing settings -->
<property name="hibernate.c3p0.validate">false</property>
<property name="hibernate.c3p0.automaticTestTable">conTestTable</property>
<!--
<property name="hibernate.c3p0.timeout">600</property>
<property name="hibernate.c3p0.maxIdleTimeExcessConnections">20</property> -->
<!-- Connection testing settings -->
<!--
<property name="hibernate.c3p0.validate">false</property>
<property name="hibernate.c3p0.idle_test_period">30</property>
<property name="hibernate.c3p0.automaticTestTable">conTestTable</property>
-->
<!-- SQL dialect -->
<property name="dialect">projectBroomKetuDataClass.dto.ImprovedMySQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <mapping class="projectBroomKetuDataClass.dto.HouseHoldDetails"/> <mapping class="projectBroomKetuDataClass.dto.MaidsDetails"/> <mapping class="projectBroomKetuDataClass.dto.HouseHoldServiceReqMap"/> <mapping class="projectBroomKetuDataClass.dto.MaidWeekTimeMap"/> <mapping class="projectBroomKetuDataClass.dto.VerificationToken"/> <mapping class="projectBroomKetuDataClass.dto.Services"/> <mapping class="projectBroomKetuDataClass.dto.ServicesOffered"/>
<mapping class="staff.CoordinatorDataClass.dto.CoordinatorDetails"/> <mapping class="resource.dataClasses.dto.HouseKeeperDetails"/> <mapping class="resource.dataClasses.dto.ElederCareTakerDetails"/> <mapping class="resource.dataClasses.dto.DriverDetails"/> <mapping class="resource.dataClasses.dto.CookDetails"/> <mapping class="resource.dataClasses.dto.BabySitterDetails"/>
<mapping class="services.dataClass.dto.BabySittingService"/> <mapping class="services.dataClass.dto.CookingService"/> <mapping class="services.dataClass.dto.DriverService"/> <mapping class="services.dataClass.dto.ElderlyCareService"/> <mapping class="services.dataClass.dto.HouseKeepingService"/>
</session-factory>
</hibernate-configuration>
以下是我的HibernateUtil类的代码片段
public static final SessionFactory getSessionFactory() {
if(null == sessionFactory)
{
//try{
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
//}
// catch(HibernateException ex){
// System.err.println("Initial SessionFactory creation failed." + ex);
// return null;
// }
}
return sessionFactory;
}
}
任何人都可以帮助我。我试图找出为什么我得到了
java.lang.ArrayIndexOutOfBoundsException:0 at org.hibernate.persister.collection.AbstractCollectionPersister.generateSelectSizeString
但无法猜测任何事情。
编辑:
我再次查看了异常的来源,这是代码片段。
protected String generateSelectSizeString(boolean isIntegerIndexed) {
String selectValue = isIntegerIndexed ?
"max(" + getIndexColumnNames()[0] + ") + 1" : // lists, arrays
"count(" + getElementColumnNames()[0] + ")"; // sets, maps, bags
return new SimpleSelect( dialect )
.setTableName( getTableName() )
.addCondition( getKeyColumnNames(), "=?" )
.addColumn( selectValue )
.toStatementString();
}
现在从调用函数generateSelectSizeString(boolean isIntegerIndexed)
开始就是
sqlSelectSizeString = generateSelectSizeString( collection.isIndexed() && !collection.isMap() );
此处 isIndexed 且 isMap 都始终返回false。所以回到方法定义
protected String generateSelectSizeString(boolean isIntegerIndexed)
isIntegerIndexed = false
因此,数组超出范围的异常发生在这一行
String selectValue = "count(" + getElementColumnNames()[0] + ")";
再次 getElementColumnNames()返回受保护的最终String数组 elementColumnNames 。 这是从构造函数内部分配的内存 org.hibernate.persister.collection.AbstractCollectionPersister
在这一行
int elementSpan = collection.getElement().getColumnSpan();
elementColumnNames = new String[elementSpan];
我无法看到getColumnSpan()是如何工作的,但肯定会返回0,这就是为什么当我们访问elementColumnNames [0]时,我们得到一个数组Out of bound异常。 有谁知道getColumnSpan()是如何工作的。我再次检查了我的代码,我认为没有任何事情没有得到解决
答案 0 :(得分:5)
Ok解决它我没有在其中一个嵌入类中编写任何字段,因为列跨度出现为0.这导致数组索引超出绑定异常。 早些时候它就像这样
import javax.persistence.Embeddable;
@Embeddable
public class HouseKeeperSuggested {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
然后我添加了一个字段
{{1}}
问题解决了