我有一个连接到 mysql 服务器的 Play 应用程序,在模型中我有一些属性,我想将它们保存为 DateTimes,但是使用 java.sql.Timestamp 会在我的演化中生成用于创建表的属性
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 错误:
We got the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6), modified_time datetime(6), createdby_id bigint, mo' at line 21 [ERROR:1064, SQLSTATE:42000], while trying to run this SQL script:
我了解到是大小参数 (6) 导致了问题,并且能够通过使用 java.sql.Date 来避免它(因为它不会在演化中产生)是否有其他人经历过这种情况并知道一种方法在这些条件下存储日期时间?
最佳答案
我能够通过使用 @Column 注释来定义 sql 中的类型来解决这个问题。
@Column(columnDefinition = "datetime")
public Timestamp createdAt;
关于java - 在 mysql 服务器 Play Framework 中存储日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31196852/