org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是java.lang.StringIndexOutOfBoundsException:0

时间:2017-02-15 17:38:32

标签: java hibernate jsp spring-mvc

我使用以下内容:

  • Netbeas 8.2
  • Spring 4.3.5
  • Apache Tomcat 8
  • Hibernate 4.3.1

我遇到了 java.lang.StringIndexOutOfBoundsException:

的问题

这是我的springMVC.xml(servlet)

<context:component-scan base-package="com.tricas.controllers" />
<mvc:annotation-driven />

<context:annotation-config />
<context:component-scan base-package="com" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
    <value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
    <value>.jsp</value>
</property>       
</bean>    

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/cobranzas" />
<property name="username" value="root" />
<property name="password" value="12345" />
</bean>

<bean id="sessionFactory"
  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
    <list>                
        <value>com.tricas.models.Perfil</value>
    </list>            
</property>
<property name="packagesToScan" value="com.tricas.models" />
<property name="hibernateProperties">
    <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.enable_lazy_load_no_trans">true</prop>                
        <prop key="format_sql">true</prop>
        <prop key="use_sql_comments">true</prop>                
    </props>
</property>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

这是我的web.xml

<servlet>
    <servlet-name>spring-web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/springMVC.xml</param-value>
</init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
   <servlet-name>spring-web</servlet-name>
   <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
  <welcome-file>
    verusuarios.html
  </welcome-file>
</welcome-file-list>

<session-config>
  <session-timeout>
    30
  </session-timeout>
</session-config>

这是我的模型Anexo.class

public class Anexo implements Serializable {

@OneToMany(mappedBy = "encargado")
private Collection<Caja> cajaCollection;

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "idanexo")
private Integer idanexo;
@Column(name = "nombre")
private String nombre;
@Column(name = "apepat")
private String apepat;
@Column(name = "apemat")
private String apemat;
@Column(name = "tipodocumento")
private String tipodocumento;
@Column(name = "numdocumento")
private String numdocumento;
@Column(name = "direccion")
private String direccion;
@Column(name = "aahh")
private String aahh;
@Column(name = "cpm")
private String cpm;
@Column(name = "sector")
private String sector;
@Column(name = "referencia")
private String referencia;
@Column(name = "telefono")
private String telefono;
@Column(name = "celular")
private String celular;
@Column(name = "edad")
private Integer edad;
@Column(name = "fechanac")
@Temporal(TemporalType.TIMESTAMP)
private Date fechanac;
@Column(name = "fechareg")
@Temporal(TemporalType.TIMESTAMP)
private Date fechareg;
@Column(name = "sexo")
private Character sexo;
@Column(name = "email")
private String email;
@Column(name = "tipoanexo")
private String tipoanexo;
@Column(name = "codven")
private String codven;
@Column(name = "estcivil")
private String estcivil;
@Column(name = "conyuge")
private String conyuge;
@Column(name = "dniconyu")
private String dniconyu;
@Column(name = "direccionconyu")
private String direccionconyu;
@Column(name = "ocupacionconyu")
private String ocupacionconyu;
@Column(name = "cpropia")
private String cpropia;
@Column(name = "zona")
private String zona;
@Column(name = "sueldo")
private Integer sueldo;
@Column(name = "tienda")
private String tienda;
@JoinColumn(name = "iddistrito", referencedColumnName = "iddistrito")
@ManyToOne
private Distrito iddistrito;
@OneToMany(mappedBy = "idanexo")
private Collection<Ocupacion> ocupacionCollection;
@OneToMany(mappedBy = "idanexo")
private Collection<Operacion> operacionCollection;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idanexo")
private Collection<Credito> creditoCollection;
@OneToMany(mappedBy = "idanexo")
private Collection<Creditoaval> creditoavalCollection;
@OneToMany(mappedBy = "idanexo")
private Collection<Conceptos> conceptosCollection;
@OneToMany(mappedBy = "idanexo")
private Collection<Usuario> usuarioCollection;

public Anexo() {
}
/* Getters and Setters*/

我的AnexoDaoImpl

@Repository
@Transactional
public class AnexoDaoImpl implements AnexoDao{

@Autowired
private SessionFactory session;

@Override
public List<Anexo> anexos() {
    return session.getCurrentSession().createQuery("from Anexo ").list();               
}

@Override
public void ingresarModificar(Anexo anexo) {
    session.getCurrentSession().saveOrUpdate(anexo);
}

我的AnexoService

@Service("anexoService")
public class AnexoService {

@Autowired
private AnexoDao anexodao;

@Transactional
public List<Anexo> getAllAnexo() {
    return anexodao.anexos();
}

@Transactional
public void crearModificar(Anexo u) {
    anexodao.ingresarModificar(u);
}

我的AnexoController

@Controller("anexoController")
public class AnexoController {

@Autowired
private AnexoService anexoserv;

@RequestMapping(value = "/veranexos", method = RequestMethod.GET)
public String listPersons(Model model) {
    List<Anexo> list = anexoserv.getAllAnexo();
    model.addAttribute("anexo", new Anexo());
    model.addAttribute("list", list);
    return "anexo";
}

@RequestMapping(value = "/anexo/add", method = RequestMethod.POST)
public String addPerson(@ModelAttribute("anexo") Anexo p) {
    anexoserv.crearModificar(p);
    return "redirect:/veranexos";
}

@RequestMapping("/edita/{idanexo}")
public String editPerson(@PathVariable("idanexo") int id, Model model) {
    model.addAttribute("anexo", anexoserv.getById(id));
    model.addAttribute("list", anexoserv.getAllAnexo());
    return "anexo";
}

@RequestMapping("/removea/{idanexo}")
public String removePerson(@PathVariable("idanexo") int id) {
    Anexo p = new Anexo();
    p = anexoserv.getById(id);
    anexoserv.eliminar(p);
    return "redirect:/veranexos";
}

最后我的观点是anexo.jsp

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:646)
at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:78)
at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:33)
at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$2.doExtract(VarcharTypeDescriptor.java:74)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:259)
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249)
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:334)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1695)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1627)
at org.hibernate.loader.Loader.getRow(Loader.java:1514)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:725)
at org.hibernate.loader.Loader.processResultSet(Loader.java:952)
at org.hibernate.loader.Loader.doQuery(Loader.java:920)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2551)
at org.hibernate.loader.Loader.doList(Loader.java:2537)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
at org.hibernate.loader.Loader.list(Loader.java:2362)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:229)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1260)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at com.tricas.dao.AnexoDaoImpl.anexos(AnexoDaoImpl.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy799.anexos(Unknown Source)
at com.tricas.services.AnexoService.getAllAnexo(AnexoService.java:19)
at com.tricas.services.AnexoService$$FastClassBySpringCGLIB$$fb0c453f.invoke(<generated>)

请问我可以帮助我吗?

0 个答案:

没有答案