我有一个实体
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
@Entity
@Table(name = "t_org")
public class Organization {
/**
* id of the organization.
*/
@Id
@GeneratedValue(generator = "UUID")
@Column(name = "c_id", columnDefinition = "BINARY(16) DEFAULT (UUID_TO_BIN(UUID(), TRUE))")
private UUID id;
/**
* legal name of the organization.
*/
@Column(name = "c_legal_name", nullable = false, unique = true)
private String legalName;
/**
* alias name of the organization.
*/
@Column(name = "c_alias", nullable = false, unique = true)
private String alias;
/**
* timestamp when the organization was created.
*/
@Column(name = "c_date", insertable = false, updatable = false,
columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
nullable = false)
private Instant ts;
}
现在,当我从服务保存此实体时,以及当我想通过调用saveAndFlush(orgObject).getTs()访问时间戳时;
时间戳总是空的,但是我可以看到它被保存在数据库中,但是jpa没有返回它。
我试着用@CreationTimestamp注解它,但这将设置jvm的时间戳,我需要db的时间戳。
1条答案
按热度按时间mqkwyuun1#
我试过了,这是获取时间戳。我创建了一个实体类,叫做post。并为它创建了API控制器和服务类。这是完整的代码。
The screenshot
希望这个有用。