数据表为:
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类型的值呀?
@Column(name = "createtime") 里面 好像 还有设置属性的值得 @Temporal(TemporalType.TIMESTAMP) 你可以百度下试试