Java 在mysql服务器播放框架中存储datetime
我有一个连接到mysql服务器的Play应用程序,在这些模型中,我有一些属性希望保存为DateTimes,但是使用java.sql.Timestamp会在我的演进中生成属性,用于创建表Java 在mysql服务器播放框架中存储datetime,java,mysql,datetime,playframework-2.0,Java,Mysql,Datetime,Playframework 2.0,我有一个连接到mysql服务器的Play应用程序,在这些模型中,我有一些属性希望保存为DateTimes,但是使用java.sql.Timestamp会在我的演进中生成属性,用于创建表 create table delivery ( id bigint auto_increment not null, deleted tinyint(1) default 0, description
create table delivery (
id bigint auto_increment not null,
deleted tinyint(1) default 0,
description varchar(500),
notes varchar(1000),
account_id bigint,
customer_id bigint,
sender_id bigint,
recipient_id bigint,
delivery_status_id bigint,
delivery_type_id bigint,
package_type_id bigint,
item_type_id bigint,
call_date datetime(6),
pickup_date datetime(6),
delivery_date datetime(6),
no_of_pieces integer,
cust_type integer,
payment_type integer,
way_bill integer,
created_time date,
modified_time date,
createdby_id bigint,
modifiedby_id bigint,
constraint pk_delivery primary key (id))
这进而导致mysql错误:
我们得到以下错误:您的SQL语法有错误;
检查与MySQL服务器版本对应的手册,了解
使用near'(6)、modified_time datetime(6)、createdby_id的正确语法
在第21行[ERROR:1064,SQLSTATE:42000]处输入bigint,mo',同时尝试
运行以下SQL脚本:
我了解到是大小参数(6)导致了问题,并能够通过使用java.sql.Date避免它(因为它不会在演进中产生)有没有其他人经历过这种情况,并且知道在这种情况下存储日期时间的方法?我能够通过使用@Column注释在sql中定义类型来解决这个问题
@Column(columnDefinition = "datetime")
public Timestamp createdAt;
可能我的答案有点晚,但您可以尝试使用以下注释:@CreatedTimestamp或@UpdatedTimestamp。我已经用游戏测试过了!框架2.3.x
@Column(name = "created")
@CreatedTimestamp
protected Date created;
@Column(name = "updated")
@UpdatedTimestamp
protected Date updated;
请发布更多SQL脚本。另外,您的应用程序试图执行的确切查询是什么?我不明白您为什么坚持使用java DateTime,您能解释一下吗?我想存储一个DateTime,而不仅仅是日期或时间,而java.sql.date和java.sql.Timestamp都是导致此问题的原因