postgresql 错误:运算符不存在:字符变化 = bytea

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10546344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:29:36  来源:igfitidea点击:

ERROR: operator does not exist: character varying = bytea

hibernatepostgresql

提问by rajshekhar

I have a table in postgres with the following structure

我在 postgres 中有一个表,其结构如下

CREATE TABLE rpaul."HK_LOGIN_DETAILS"
(
  "HK_LOGIN_DETAILS_ID" bigint NOT NULL,
  "HK_LOGIN_DETAILS_USERNAME" character varying(10) NOT NULL,
  "HK_LOGIN_DETAILS_PASSWORD" character varying(50) NOT NULL,
  CONSTRAINT "HK_LOGIN_DETAILS_PK" PRIMARY KEY ("HK_LOGIN_DETAILS_ID" ),
  CONSTRAINT "HK_LOGIN_DETAILS_UK" UNIQUE ("HK_LOGIN_DETAILS_USERNAME" )
)

And hibernate mapping for this table is as mentioned below

该表的休眠映射如下所述

<hibernate-mapping package="net.rpaul.projects.homekeeping.domain.login">
    <class name="LoginDetails" table="`HK_LOGIN_DETAILS`">
        <id name="id" column="`HK_LOGIN_DETAILS_ID`" type="long">
            <generator class="assigned" />
        </id>
        <property name="userName" type="string" column="`HK_LOGIN_DETAILS_USERNAME`" not-null="true" />
        <property name="password" type="string" column="`HK_LOGIN_DETAILS_PASSWORD`" not-null="true" />
    </class>
</hibernate-mapping>

In the LoginDetails.java, I have declared id field as long, userName and password fields as String. Still when I try to execute the following

在 LoginDetails.java 中,我已将 id 字段声明为字符串,将用户名和密码字段声明为字符串。仍然当我尝试执行以下操作时

List list =  getHibernateTemplate().find("from LoginDetails ld where ld.userName = ?", userName);

I get

我得到

ERROR: operator does not exist: character varying = bytea

错误:运算符不存在:字符变化 = bytea

I am not getting what has went wrong. Any help would be appreciated.

我不明白出了什么问题。任何帮助,将不胜感激。

回答by chavocarlos

I think you should check that your variable "userName" is not null. I experienced this message in cases like that.

我认为您应该检查您的变量“userName”是否为空。在这样的情况下,我经历了这条消息。

回答by Sergey Ponomarev

It seems that Hibernate is for some reason sending the type-parameter as bytea (or rather, probably java.sql.Types.BLOB), instead of leaving it for the server to infer or setting it to text (java.sql.Types.STRING). Here is similar issue with solution JPA lower() function on parameter

似乎 Hibernate 出于某种原因将类型参数作为 bytea(或者更确切地说,可能是 java.sql.Types.BLOB)发送,而不是将其留给服务器来推断或将其设置为文本 (java.sql.Types.细绳)。这是与参数上的解决方案JPA lower() 函数类似的问题