gpt4 book ai didi

java - Hibernate HQL 无法找到命名参数 [parameterName]

转载 作者:行者123 更新时间:2023-12-01 21:40:13 26 4
gpt4 key购买 nike

我制作了一个网络应用程序,它使用使用 spring-hibernate 搜索某些数据库记录的参数,如下所示:

enter image description here

但是当我按下按钮时,我遇到此错误org.hibernate.QueryParameterException:无法找到命名参数[nama_depan]

这是我的课,

package org.ppbni.splatter.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name="user")
public class UserAdmin implements Serializable{

@Id
@GeneratedValue
@Column(name="no_dana", unique=true, nullable=false)
private String no_dana;

@Column(name="npp")
private String npp;

@Column(name="password")
private String password;

@Column(name="nama_depan")
private String nama_depan;

@Column(name="nama_tengah")
private String nama_tengah;

@Column(name="nama_belakang")
private String nama_belakang;

@Column(name="kota")
private String kota;

@OneToOne(mappedBy="useradmin", cascade=CascadeType.ALL)
private Wafat wafat;

@OneToOne(mappedBy="useradmin", cascade=CascadeType.ALL)
private Korwil korwil;

/**other field**//

/**setter and gettter methods**/
}

这是我的 DAOImpl:

@SuppressWarnings("unchecked")
@Override
public List<UserAdmin> listAllUserAdminDafAnggota(String nama, String kota)throws Exception{
Query query = getSession().createQuery("from UserAdmin where (nama_depan = :namadepan or nama_tengah = :namatengah or nama_belakang = :namabelakang) or kota = :kota");
query.setParameter("nama_depan", nama);
query.setParameter("nama_tengah", nama);
query.setParameter("nama_belakang", nama);
query.setParameter("kota", kota);

List<UserAdmin> result = query.list();

return result;
}

这是我的 Controller ,

@RequestMapping(value="/user/daftar-anggota-ppbni.html")
public ModelAndView userDaftarAnggotaPPBNI(ModelMap model, @RequestParam(value="nama") String nama, @RequestParam(value="kota") String kota)throws Exception{

List<UserAdmin> useradmin = userService.listAllUserAdminDafAnggota(nama, kota);
model.addAttribute("useradmin", useradmin);
return userDaftarAnggota(model);

}

这是错误,

org.hibernate.QueryParameterException: could not locate named parameter [nama_depan]
at org.hibernate.engine.query.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:101)
at org.hibernate.engine.query.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:107)
at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:460)
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:430)
at org.ppbni.splatter.dao.impl.UserDaoImpl.listAllUserAdminDafAnggota(UserDaoImpl.java:98)
at org.ppbni.splatter.service.impl.UserServiceImpl.listAllUserAdminDafAnggota(UserServiceImpl.java:69)
at org.ppbni.splatter.web.controller.UserController.userDaftarAnggotaPPBNI(UserController.java:100)
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 org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
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:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

最佳答案

来自 UserAdmin,其中 (nama_depan = :namadepan 或 nama_tengah = :namatenah 或 nama_belakang = :namabelakang) 或 kota = :kota

命名参数 namadepan:namadepan

您使用

query.setParameter("nama_depan", nama);
query.setParameter("nama_tengah", nama);
query.setParameter("nama_belakang", nama);

应该是

query.setParameter("namadepan", nama);
query.setParameter("namatengah", nama);
query.setParameter("namabelakang", nama);

关于java - Hibernate HQL 无法找到命名参数 [parameterName],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36592298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com