当前位置:  开发笔记 > 编程语言 > 正文

无法实例化集合持久性

如何解决《无法实例化集合持久性》经验,为你挑选了1个好方法。

嗨,我一直在我的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.(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.(AbstractCollectionPersister.java:528)
    at org.hibernate.persister.collection.BasicCollectionPersister.(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

 



    

        
        com.mysql.jdbc.Driver

        jdbc:mysql://127.0.0.1:3306/b#%^^DB


        ****

        ******



       
                org.hibernate.connection.C3P0ConnectionProvider         1
        15
        300
        50
        30

                

        false
        conTestTable 

        
        
        
        
        projectBroomKetuDataClass.dto.ImprovedMySQLDialect

        
        org.hibernate.cache.internal.NoCacheProvider

        
        true

                  update                                                     
                                                    
                                                 
    


下面是我的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() );

这里isIndexedisMap都返回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()是如何工作的.我再次检查了我的代码,我认为没有任何事情没有得到解决



1> Akash Pandey..:

好的解决了我没有在其中一个嵌入类中编写任何字段,因为列跨度出现为0.这导致数组索引超出绑定异常.之前它就像这样

import javax.persistence.Embeddable;

@Embeddable
public class HouseKeeperSuggested {


}

然后我添加了一个字段

import javax.persistence.Embeddable;

@Embeddable
public class HouseKeeperSuggested {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

问题解决了

推荐阅读
跟我搞对象吧
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有