首页新闻找找看学习计划

HQL查询,怎么处理datetime类型数据

0
悬赏园豆:10 [待解决问题]

数据表为:
CREATE TABLE orders (

createtime datetime DEFAULT NULL,
...

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

映射文件如下:

@Entity
@Table(name = "orders", schema = "test", catalog = "")
public class OrdersEntity {

private Timestamp createtime;


public OrdersEntity() {    }

public OrdersEntity(int id, String number, Timestamp createtime, String note) {
    this.id = id;
    this.number = number;
    this.createtime =createtime;
    this.note = note;
}

@Column(name = "createtime")
public Timestamp getCreatetime() {
    return createtime;
}

public void setCreatetime(Timestamp createtime) {
    this.createtime = createtime;
}

}

HQL查询:
public void testUser2(){
String hql="select new OrdersEntity(id,number,createtime,note) from OrdersEntity where id=1";
OrdersEntity entity= (OrdersEntity) session.createQuery(hql).uniqueResult();
System.out.println(entity);
}

报错:
java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.ifox.OrdersEntity]. Expected arguments are: int, java.lang.String, java.util.Date, java.lang.String [select new OrdersEntity(id,number,createtime,note) from com.ifox.OrdersEntity where id=1]

问题:
我的HQL中怎样传这个Timestamp类型的值呀?

cxiaoluab的主页 cxiaoluab | 初学一级 | 园豆:26
提问于:2019-01-25 00:14
< >
分享
所有回答(2)
0

看下数据库中createtime字段的类型

流年飞雨 | 园豆:1923 (小虾三级) | 2019-01-27 02:43

试试把createtime改成Date类型

支持(0) 反对(0) 流年飞雨 | 园豆:1923 (小虾三级) | 2019-01-27 02:44
0

@Column(name = "createtime") 里面 好像 还有设置属性的值得 @Temporal(TemporalType.TIMESTAMP) 你可以百度下试试

^keepHungry$ | 园豆:610 (小虾三级) | 2019-01-28 16:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册