首页 新闻 会员 周边 捐助

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
< >
分享
所有回答(1)
0

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

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