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

标签 java entity-framework hibernate ebean

在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/

相关文章:

java - 如何使用 Jsoup 和/或正则表达式 Java 从 URL 中删除 html 标签

java - 为什么我的 @Scheduled Spring Boot 任务在 Azure 中运行不一致?

c# - ASP.NET MVC : How to properly reference custom object to ApplicationUser?

c# - 无法在 .Net Standard 2.1 项目中添加 EF 6.4 迁移

java - 将大数据从数据库导出到 CSV

java - 我可以使用哪个 Java 工作流框架将其与 gui 绑定(bind)

java - 在 Java 中使用 servlet 获取 boolean 值 isAdmin 值

.net - 在程序集“SMSApp”中找到了多个迁移配置类型。指定要使用的名称

regex - 如何在JPQL中应用正则表达式?

hibernate - 我可以让 Hibernate 用查询名称来标记它生成的 SQL 吗?