Search code examples
javaentity-frameworkhibernateebean

How remove Ebean ORM Entity property


In java model Entity have the below property

@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;
}

but in DB table only have a part of property

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;

I want to know in ebean how to remove some property use annotation


Solution

  • Add @Transient annotation

    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.