相关疑难解决方法(0)

如何使用强制转换编写hql查询?

我需要使用HQL,两者都具有共同的列合并2个表,但table1共同的列是integertable2普通列String

例如,

select a.id as id,a.name as name,b.address as address 
from Personal as a,Home as b 
where a.id=b.studid
Run Code Online (Sandbox Code Playgroud)

这里a.id是一个integer同时b.stduid是一个string,但两列的数据是一样的.

如何使用hql查询获取查询结果?

java hibernate hql

38
推荐指数
4
解决办法
7万
查看次数

PostgreSQL枚举和Java枚举之间的Hibernate映射

背景

  • Spring 3.x,JPA 2.0,Hibernate 4.x,Postgresql 9.x.
  • 使用我要映射到Postgresql枚举的枚举属性处理Hibernate映射类.

问题

查询枚举列上的where子句会引发异常.

org.hibernate.exception.SQLGrammarException: could not extract ResultSet
... 
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: movedirection = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

代码(大大简化)

SQL:

create type movedirection as enum (
    'FORWARD', 'LEFT'
);

CREATE TABLE move
(
    id serial NOT NULL PRIMARY KEY,
    directiontomove movedirection NOT NULL
);
Run Code Online (Sandbox Code Playgroud)

Hibernate映射类:

@Entity
@Table(name = "move")
public class Move {

    public …
Run Code Online (Sandbox Code Playgroud)

java postgresql enums annotations hibernate-mapping

25
推荐指数
2
解决办法
1万
查看次数

带有命名参数的Hibernate Native Query问题

我有Hibernate Native Query的问题.我有一个选择数组切片的SELECT(PostgreSQL数据库).

问题是hibernate识别以下部分:"SELECT my_array [1:300] ..."中的":300"作为命名参数,我得到以下异常:并未设置所有命名参数.

我试图用':','::'来逃避冒号(:),但没有成功.

Hibernate版本是3.2

java sql postgresql hibernate

8
推荐指数
1
解决办法
4002
查看次数

标签 统计

java ×3

hibernate ×2

postgresql ×2

annotations ×1

enums ×1

hibernate-mapping ×1

hql ×1

sql ×1