gpt4 book ai didi

java - 如何删除Ebean ORM实体属性

转载 作者:行者123 更新时间:2023-12-01 09:58:19 25 4
gpt4 key购买 nike

在java模型实体中具有以下属性

@Entity
@Table(name = "device_key")
public class UserKey implements Serializable {
private long id;

@Column(name = "device_id")
private int deviceId;

@Column(name = "device_hub_id")
private int serverId;

private byte status;

@Column(name = "user_id")
private int peopleSeq; //人员序号

private short tempSeq; //临时证

@Column(name = "from_date")
private String startDate;

@Column(name = "to_date")
private String endDate;

@Column(name = "from_time")
private String startTime;

@Column(name = "to_time")
private String endTime;

private String peopleName;

private short attr;
}

但数据库表中只有部分属性

CREATE TABLE `device_key` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`device_id` bigint(20) DEFAULT NULL,
`user_id` bigint(20) DEFAULT NULL,
`device_hub_id` bigint(20) DEFAULT NULL,
`from_date` date DEFAULT NULL,
`to_date` date DEFAULT NULL,
`from_time` time DEFAULT NULL,
`to_time` time DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`last_time` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_key_device` (`device_id`),
CONSTRAINT `FK_key_device` FOREIGN KEY (`device_id`) REFERENCES `device` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4;

我想知道在ebean中如何删除一些属性使用注释

最佳答案

添加@Transient注释

Transient Fields Transient entity fields are fields that do not participate in persistence and their values are never stored in the database (similar to transient fields in Java that do not participate in serialization). Static and final entity fields are always considered to be transient. Other fields can be declared explicitly as transient using either the Java transient modifier (which also affects serialization) or the JPA @Transient annotation (which only affects persistence):

@Entity
public class EntityWithTransientFields {
static int transient1; // not persistent because of static
final int transient2 = 0; // not persistent because of final
transient int transient3; // not persistent because of transient
@Transient int transient4; // not persistent because of @Transient
}

The above entity class contains only transient (non persistent) entity fields with no real content to be stored in the database.

关于java - 如何删除Ebean ORM实体属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37017332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com