无法解决财产问题3

时间:2016-05-22 19:00:08

标签: java hibernate

  

输入代码消息org.hibernate.QueryException:无法解析属性:company of com.company.location.entities.Compte [select com from com.company.location.entities.Compte com com.statuts ='actif '和com.user ='admin'和com.pwd ='admin'和com.personnels.id in(从com.company.location.entities.Personnels p中选择p.id,其中statuts ='actif')]

描述Le serveuranrencontréuneerreur interne qui l''aempêchédesatisfairelarequête。

例外

javax.servlet.ServletException: org.hibernate.QueryException: could not resolve property: company of: com.company.location.entities.Compte [select com from com.company.location.entities.Compte  com where com.statuts='actif' and  com.user='admin' and com.pwd='admin' and com.personnels.id in (select p.id from com.company.location.entities.Personnels p where statuts='actif')]
    javax.faces.webapp.FacesServlet.service(Unknown Source)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:233)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
cause mère

javax.faces.el.EvaluationException: org.hibernate.QueryException: could not resolve property: company of: com.company.location.entities.Compte [select com from com.company.location.entities.Compte  com where com.statuts='actif' and  com.user='admin' and com.pwd='admin' and com.personnels.id in (select p.id from com.company.location.entities.Personnels p where statuts='actif')]
    javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(Unknown Source)
    com.sun.faces.application.ActionListenerImpl.processAction(Unknown Source)
    javax.faces.component.UICommand.broadcast(Unknown Source)
    javax.faces.component.UIViewRoot.broadcastEvents(Unknown Source)
    javax.faces.component.UIViewRoot.processApplication(Unknown Source)
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(Unknown Source)
    com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
    com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
    javax.faces.webapp.FacesServlet.service(Unknown Source)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:70)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:233)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

@Override
public Compte findComptePer(String user, String pwd, Integer id) {
    String req="select com from Compte  com where com.statuts='actif' and  com.user='"+user+"' and com.pwd='"+pwd+"' "
            + "and com.personnels.id in (select p.id from Personnels p where statuts='actif')";
    return  (Compte) sessionfactory.getCurrentSession().createQuery(req).uniqueResult();

}

实体

enter code  @Entity
public class Personnels implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "id_agence", referencedColumnName = "id")
private Agence agence;
private String nom;
private String prenom;
private String tel;
private String adresse;
private String statuts



@Entity
public class Compte implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "idPersonnel")
private Personnels personnels;
private String user;
private String pwd;
private String statuts;
@Temporal(TemporalType.DATE)
private Date date;
@ManyToOne
@JoinColumn(name = "id_roles")
private Roles roles;

1 个答案:

答案 0 :(得分:0)

HQL中别名com的问题。 com.company.location.entities.Compte对此别名的含义不正确。

select com from Compte com where com.statuts='actif' and com.user='"+user+"' and com.pwd='"+pwd+"' " + "and com.personnels.id in (select p.id from Personnels p where statuts='actif'

只需将其更改为compte

即可

select compte from Compte compte where compte.statuts='actif' ...

并且,请使用命名查询参数

Hibernate parameter binding examples