错误:运算符不存在:character = integer

时间:2014-03-18 09:01:36

标签: hibernate spring-mvc postgresql-9.1

这是我的DaoImpl类。我有其他表tblprofiles,其中字段电子邮件是主键。我可以将电子邮件中的tbldealusers数据作为字符类型的外键。当我运行这个程序时,我得到的错误就像

错误:运算符不存在:character = integer

与tblProfiles具有OneToMany关系的tbldealusers

 public class UserDaoImpl implements UserDao 
    {

        private SessionFactory sessionFactory;
        DealUser dealuser=new DealUser();
        private Session session=null;
        Profiles profiles=new Profiles();

        @Autowired
        public void setSessionFactory(SessionFactory sessionFactory) 
        {
            this.sessionFactory = sessionFactory;
        }

        @SuppressWarnings("unchecked")      
         public List<DealUser> getAllDealUsers() 
         {
            session =sessionFactory.getCurrentSession();
             List<DealUser> dealUsers =  (List<DealUser>) session.
                    createSQLQuery("select * from tbldealusers u ")
                    .addEntity("u", DealUser.class)
                     .list();

            return dealUsers;
         }

我的执行堆栈跟踪

Hibernate: select * from tbldealusers u
Hibernate: select profiles0_.email as email1_, profiles0_.email as email9_0_, profiles0_.firstnname as firstnname9_0_, profiles0_.lastname as lastname9_0_, profiles0_.mobile as mobile9_0_, profiles0_.notifyflash as notifyfl5_9_0_, profiles0_.is_active as is6_9_0_, profiles0_.tac_preferenceluid as tac7_9_0_, profiles0_.createddate as createdd8_9_0_, profiles0_.modifieddate as modified9_9_0_, profiles0_.createduserid as created10_9_0_, profiles0_.modifieduserid as modifie11_9_0_ from tblprofiles profiles0_ where profiles0_.email=?
2014-03-18 16:19:55 WARN  JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 42883
2014-03-18 16:19:55 ERROR JDBCExceptionReporter:78 - ERROR: operator does not exist: character = integer
Mar 18, 2014 4:19:55 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [servlet-context] in context with path [/SaveDollar] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.saveDollar.model.DealUser.profiles#1]] with root cause
org.postgresql.util.PSQLException: ERROR: operator does not exist: character = integer
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1608)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1343)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:194)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:470)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:369)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
    at org.hibernate.loader.Loader.doQuery(Loader.java:662)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
    at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
    at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
    at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
    at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
    at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
    at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:755)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
    at org.hibernate.loader.Loader.doList(Loader.java:2211)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
    at org.hibernate.loader.Loader.list(Loader.java:2090)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
    at com.saveDollar.dao.impl.UserDaoImpl.getAllDealUsers(UserDaoImpl.java:42)
    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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    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:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy24.getAllDealUsers(Unknown Source)
    at com.saveDollar.service.impl.UserServiceImpl.getAllDealUsers(UserServiceImpl.java:19)
    at com.saveDollar.controller.UserRestService.loadUsers(UserRestService.java:27)
    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.doGet(FrameworkServlet.java:827)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    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 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    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:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    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)

代码

package com.saveDollar.model;

import java.io.Serializable;
import java.sql.Time;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
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.OneToMany;
@Entity(name="tbldealusers")
public class DealUser implements Serializable 
{

    private static final long serialVersionUID = 1L;
      private int  userid;
      private String email;
      private String password;
      private int typeofuserluid;
      private boolean is_deleted;
      private Set<Profiles> profiles = new HashSet<Profiles>(0);      

      public DealUser()
      {

      }

      public DealUser(String email,String password,int typeofuserluid,boolean is_deleted,Set<Profiles> profiles)
         {

             this.email=email;
             this.password=password;
             this.typeofuserluid=typeofuserluid;
             this.is_deleted=is_deleted;
             this.profiles=profiles;

        }  
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="userid") 
    public int getUserid() 
    {
        return userid;
    }
    public void setUserid(int userid) 
    {
        this.userid = userid;
    }
    @Column(name="email") 
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    @Column(name="password") 
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @Column(name="typeofuserluid") 
    public int getTypeofuserluid() {
        return typeofuserluid;
    }
    public void setTypeofuserluid(int typeofuserluid) {
        this.typeofuserluid = typeofuserluid;
    }
    @Column(name="is_deleted") 
    public boolean isIs_deleted() {
        return is_deleted;
    }
    public void setIs_deleted(boolean is_deleted) 
    {
        this.is_deleted = is_deleted;
    }

    @OneToMany(fetch=FetchType.EAGER,mappedBy = "email",cascade=CascadeType.ALL)
    public Set<Profiles> getProfiles() 
    {
        return profiles;
    }

    public void setProfiles(Set<Profiles> profiles) 
    {
        this.profiles = profiles;
    }
}

请提出任何建议。请提前感谢您的宝贵建议

0 个答案:

没有答案