Rafael_Guerreiro 14 de out. de 2015
Pode me mostrar duas coisas?
1: A entidade Usuario
2: Tente executar isso:
private Usuario buscaUsuarioPorLogin ( String login ) {
return FacesContextUtil .getRequestSession ()
.createCriteria ( Usuario .class ,"usuario" )
.add ( Property .forName ( "usuario.login" ) .eq ( login )) ;
}
rafael145a 14 de out. de 2015
Segue a entidade Usuario
import javax.persistence.Column ;
import javax.persistence.Entity ;
import javax.persistence.FetchType ;
import javax.persistence.GeneratedValue ;
import javax.persistence.GenerationType ;
import javax.persistence.Id ;
import javax.persistence.JoinColumn ;
import javax.persistence.ManyToOne ;
import javax.persistence.Table ;
@Entity
@Table ( name = "usuario"
, schema = "public"
)
public class Usuario implements java . io . Serializable {
private int idUser ;
private TipoUser tipoUser ;
private String login ;
private String senha ;
private String nome ;
private String email ;
public Usuario () {
}
public Usuario ( int idUser ) {
this . idUser = idUser ;
}
public Usuario ( int idUser , TipoUser tipoUser , String login , String senha , String nome , String email ) {
this . idUser = idUser ;
this . tipoUser = tipoUser ;
this . login = login ;
this . senha = senha ;
this . nome = nome ;
this . email = email ;
}
@Id
@GeneratedValue ( strategy = GenerationType . IDENTITY )
@Column ( name = "idUser" , unique = true , nullable = false )
public int getIdUser () {
return this . idUser ;
}
public void setIdUser ( int idUser ) {
this . idUser = idUser ;
}
@ManyToOne ( fetch = FetchType . LAZY )
@JoinColumn ( name = "tipo" )
public TipoUser getTipoUser () {
return this . tipoUser ;
}
public void setTipoUser ( TipoUser tipoUser ) {
this . tipoUser = tipoUser ;
}
@Column ( name = "login" , length = 50 )
public String getLogin () {
return this . login ;
}
public void setLogin ( String login ) {
this . login = login ;
}
@Column ( name = "senha" )
public String getSenha () {
return this . senha ;
}
public void setSenha ( String senha ) {
this . senha = senha ;
}
@Column ( name = "nome" , length = 50 )
public String getNome () {
return this . nome ;
}
public void setNome ( String nome ) {
this . nome = nome ;
}
@Column ( name = "email" , length = 50 )
public String getEmail () {
return this . email ;
}
public void setEmail ( String email ) {
this . email = email ;
}
}
O código não da certo pelo tipo de retorno…
Obrigado
Rafael_Guerreiro 14 de out. de 2015
Certo, coloca assim então:
private Usuario buscaUsuarioPorLogin ( String login ) {
return ( Usuario ) FacesContextUtil .getRequestSession ()
.createCriteria ( Usuario .class ,"usuario" )
.add ( Property .forName ( "usuario.login" ) .eq ( login )) .uniqueResult () ;
}
rafael145a 14 de out. de 2015
Deu o mesmo erro.
Segue Stack trace completo:
javax . faces . el . EvaluationException : org . hibernate . exception . SQLGrammarException : ERROR : column this_ . iduser does not exist
Posição : 29
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 101 )
at com . sun . faces . application . ActionListenerImpl . processAction ( ActionListenerImpl . java : 102 )
at javax . faces . component . UICommand . broadcast ( UICommand . java : 315 )
at javax . faces . component . UIViewRoot . broadcastEvents ( UIViewRoot . java : 790 )
at javax . faces . component . UIViewRoot . processApplication ( UIViewRoot . java : 1282 )
at com . sun . faces . lifecycle . InvokeApplicationPhase . execute ( InvokeApplicationPhase . java : 81 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 101 )
at com . sun . faces . lifecycle . LifecycleImpl . execute ( LifecycleImpl . java : 118 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 646 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 291 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . tomcat . websocket . server . WsFilter . doFilter ( WsFilter . java : 52 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 239 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 368 )
at org . springframework . security . web . access . intercept . FilterSecurityInterceptor . invoke ( FilterSecurityInterceptor . java : 109 )
at org . springframework . security . web . access . intercept . FilterSecurityInterceptor . doFilter ( FilterSecurityInterceptor . java : 83 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . access . ExceptionTranslationFilter . doFilter ( ExceptionTranslationFilter . java : 97 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . session . SessionManagementFilter . doFilter ( SessionManagementFilter . java : 100 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . authentication . AnonymousAuthenticationFilter . doFilter ( AnonymousAuthenticationFilter . java : 78 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . servletapi . SecurityContextHolderAwareRequestFilter . doFilter ( SecurityContextHolderAwareRequestFilter . java : 54 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . savedrequest . RequestCacheAwareFilter . doFilter ( RequestCacheAwareFilter . java : 35 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . authentication . www . BasicAuthenticationFilter . doFilter ( BasicAuthenticationFilter . java : 177 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . authentication . AbstractAuthenticationProcessingFilter . doFilter ( AbstractAuthenticationProcessingFilter . java : 187 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . authentication . logout . LogoutFilter . doFilter ( LogoutFilter . java : 105 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . context . SecurityContextPersistenceFilter . doFilter ( SecurityContextPersistenceFilter . java : 79 )
at org . springframework . security . web . FilterChainProxy $ VirtualFilterChain . doFilter ( FilterChainProxy . java : 380 )
at org . springframework . security . web . FilterChainProxy . doFilter ( FilterChainProxy . java : 169 )
at org . springframework . web . filter . DelegatingFilterProxy . invokeDelegate ( DelegatingFilterProxy . java : 237 )
at org . springframework . web . filter . DelegatingFilterProxy . doFilter ( DelegatingFilterProxy . java : 167 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 239 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 219 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 106 )
at org . apache . catalina . authenticator . AuthenticatorBase . invoke ( AuthenticatorBase . java : 502 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 142 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 79 )
at org . apache . catalina . valves . AbstractAccessLogValve . invoke ( AbstractAccessLogValve . java : 617 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 88 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 518 )
at org . apache . coyote . http11 . AbstractHttp11Processor . process ( AbstractHttp11Processor . java : 1091 )
at org . apache . coyote . AbstractProtocol $ AbstractConnectionHandler . process ( AbstractProtocol . java : 668 )
at org . apache . tomcat . util . net . AprEndpoint $ SocketProcessor . doRun ( AprEndpoint . java : 2463 )
at org . apache . tomcat . util . net . AprEndpoint $ SocketProcessor . run ( AprEndpoint . java : 2452 )
at java . util . concurrent . ThreadPoolExecutor . runWorker ( ThreadPoolExecutor . java : 1142 )
at java . util . concurrent . ThreadPoolExecutor $ Worker . run ( ThreadPoolExecutor . java : 617 )
at org . apache . tomcat . util . threads . TaskThread $ WrappingRunnable . run ( TaskThread . java : 61 )
at java . lang . Thread . run ( Thread . java : 745 )
Caused by : org . hibernate . exception . SQLGrammarException : ERROR : column this_ . iduser does not exist
Posição : 29
at org . hibernate . exception . internal . SQLStateConversionDelegate . convert ( SQLStateConversionDelegate . java : 122 )
at org . hibernate . exception . internal . StandardSQLExceptionConverter . convert ( StandardSQLExceptionConverter . java : 47 )
at org . hibernate . engine . jdbc . spi . SqlExceptionHelper . convert ( SqlExceptionHelper . java : 125 )
at org . hibernate . engine . jdbc . spi . SqlExceptionHelper . convert ( SqlExceptionHelper . java : 110 )
at org . hibernate . engine . jdbc . internal . proxy . AbstractStatementProxyHandler . continueInvocation ( AbstractStatementProxyHandler . java : 129 )
at org . hibernate . engine . jdbc . internal . proxy . AbstractProxyHandler . invoke ( AbstractProxyHandler . java : 81 )
at com . sun . proxy .$ Proxy51 . executeQuery ( Unknown Source )
at org . hibernate . loader . Loader . getResultSet ( Loader . java : 1978 )
at org . hibernate . loader . Loader . doQuery ( Loader . java : 829 )
at org . hibernate . loader . Loader . doQueryAndInitializeNonLazyCollections ( Loader . java : 289 )
at org . hibernate . loader . Loader . doList ( Loader . java : 2463 )
at org . hibernate . loader . Loader . doList ( Loader . java : 2449 )
at org . hibernate . loader . Loader . listIgnoreQueryCache ( Loader . java : 2279 )
at org . hibernate . loader . Loader . list ( Loader . java : 2274 )
at org . hibernate . loader . criteria . CriteriaLoader . list ( CriteriaLoader . java : 122 )
at org . hibernate . internal . SessionImpl . list ( SessionImpl . java : 1483 )
at org . hibernate . internal . CriteriaImpl . list ( CriteriaImpl . java : 374 )
at org . hibernate . internal . CriteriaImpl . uniqueResult ( CriteriaImpl . java : 396 )
at br . com . peretz . portalfinanceiro . controller . MbUsuario . buscaUsuarioPorLogin ( MbUsuario . java : 56 )
at br . com . peretz . portalfinanceiro . controller . MbUsuario . editUsuario ( MbUsuario . java : 49 )
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 : 483 )
at org . apache . el . parser . AstValue . invoke ( AstValue . java : 247 )
at org . apache . el . MethodExpressionImpl . invoke ( MethodExpressionImpl . java : 267 )
at com . sun . faces . facelets . el . TagMethodExpression . invoke ( TagMethodExpression . java : 105 )
at javax . faces . component . MethodBindingMethodExpressionAdapter . invoke ( MethodBindingMethodExpressionAdapter . java : 87 )
... 56 more
Caused by : org . postgresql . util . PSQLException : ERROR : column this_ . iduser does not exist
Posição : 29
at org . postgresql . core . v3 . QueryExecutorImpl . receiveErrorResponse ( QueryExecutorImpl . java : 2103 )
at org . postgresql . core . v3 . QueryExecutorImpl . processResults ( QueryExecutorImpl . java : 1836 )
at org . postgresql . core . v3 . QueryExecutorImpl . execute ( QueryExecutorImpl . java : 257 )
at org . postgresql . jdbc2 . AbstractJdbc2Statement . execute ( AbstractJdbc2Statement . java : 512 )
at org . postgresql . jdbc2 . AbstractJdbc2Statement . executeWithFlags ( AbstractJdbc2Statement . java : 388 )
at org . postgresql . jdbc2 . AbstractJdbc2Statement . executeQuery ( AbstractJdbc2Statement . java : 273 )
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 : 483 )
at org . hibernate . engine . jdbc . internal . proxy . AbstractStatementProxyHandler . continueInvocation ( AbstractStatementProxyHandler . java : 122 )
... 79 more
Segue a query do criteria gerado pelo log:
/* criteria query */ select
this_ . idUser as idUser0_0_ ,
this_ . email as email0_0_ ,
this_ . login as login0_0_ ,
this_ . nome as nome0_0_ ,
this_ . senha as senha0_0_ ,
this_ . tipo as tipo0_0_
from
public . usuario this_
where
this_ . login = ?
Já verifiquei o parâmetro tbm, esta sendo passado certo…
Obrigado
Rafael_Guerreiro 14 de out. de 2015
Se você pegar esse Select e trocar o ? pelo parâmetro, funciona?
Tente remover o schema=“public”…
rafael145a 14 de out. de 2015
Estranho, testei direto no PgAdmin ele deu o mesmo erro, ai alterei o idUser para “idUser” (com aspas) e funcionou.
Alguma ideia de como coloco essas aspas no hibernate?
rafael145a 14 de out. de 2015
Eu resolvi o problema renomeando a coluna do banco para iduser minusculo, não sei se é um problema do postgre, mas parece que ele não reconhece a letra maiúscula se não colocar o nome entre aspas.
Seria interessante descobrimos o porque disso, não sei se é conceitual do postgre.