java实体添加构造函数_java–尽管已定义,但没有实体的默认构
造函数
我试图使⽤Hibernate与
Spring来创建⼀个Web应⽤程序.在尝试创建登录表单时,我搜索⼀个帐户并尝试通过调⽤在AccountDAOImpl中创建它
帐户帐号= accountDAO.findAccount(⽤户名);
我在⾏上得到⼀个错误:
return(Account)criteria.uniqueResult();
错误是org.hibernate.InstantiationException:没有实体的默认构造函数
实体表具有指定的⽆参数构造函数
public Account(){}
还有另⼀个带参数的构造函数,但即使我将其注释掉,错误仍然会发⽣.
我在这⾥完全迷失了,错误信息很明显,但即使我做了应该解决的问题,它仍然会发⽣.有谁知道可能是什么原因?
整个痕迹:
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.doFilter An internal error occurred
while trying to authenticate the user.
org.springframework.security.authentication.InternalAuthenticationServiceException: No default constructor for entity: :
at
org.springframework.security.authentication.ieveUser(DaoAuthenticationProvider.java:126)
at
org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthe
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:167)
java接口有没有构造方法
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:192)
at
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswor
at
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessing
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at
org.springframework.t.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at
org.springframework.t.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerInte
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:3
46)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.tor.CoyoteAdapter.service(CoyoteAdapter.java:341)
at http11.Http11Processor.service(Http11Processor.java:783)
at AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
at at.util.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
at at.util.SocketProcessorBase.run(SocketProcessorBase.java:49)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at at.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.InstantiationException: No default constructor for entity: : ity.Account
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:81)
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:101)
at org.ity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:635)
at org.ity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:4648)
at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1483)
at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1467)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1645)
at org.hibernate.Row(Loader.java:1543)
at org.hibernate.RowFromResultSet(Loader.java:727)
at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
at org.hibernate.loader.Loader.doQuery(Loader.java:930)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
at org.hibernate.loader.Loader.doList(Loader.java:2610)
at org.hibernate.loader.Loader.doList(Loader.java:2593)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
at org.hibernate.loader.Loader.list(Loader.java:2417)
at org.iteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:385)
pany.dao.impl.AccountDAOImpl.findAccount(AccountDAOImpl.java:24)
flect.NativeMethodAccessorImpl.invoke0(Native Method)
flect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
flect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at flect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at
ansaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at
ansaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:28
at ansaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy91.findAccount(Unknown Source)
pany.authentication.MyDBAuthenticationService.loadUserByUsername(MyDBAuthenticationService.java:25)
at
org.springframework.security.authentication.ieveUser(DaoAuthenticationProvider.java:114)
... 39 more
最佳答案 我离开了问题,离开了⼏个⼩时.当我回来再次尝试时,⼀切都按预期⼯作.我仍然不确定这⾥的核⼼问题是什么,但是我认为旧的“你
试过把它关掉然后重新开启”有时甚⾄在编程中都适⽤.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。