Created
November 20, 2020 13:27
-
-
Save susimsek/9991e582ddb7040d0f79fd5331a1d044 to your computer and use it in GitHub Desktop.
Using Basenin Entity in Jpa With Dto Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuperBuilder | |
@Setter | |
@Getter | |
@NoArgsConstructor | |
@AllArgsConstructor | |
@MappedSuperclass | |
public class BaseEntity { | |
@Id | |
@GeneratedValue(generator = "UUID") | |
@GenericGenerator( | |
name = "UUID", | |
strategy = "org.hibernate.id.UUIDGenerator" | |
) | |
@Type(type="org.hibernate.type.UUIDCharType") | |
@Column(length = 36, columnDefinition = "varchar", updatable = false, nullable = false ) | |
private UUID id; | |
@Version | |
private Long version; | |
@CreationTimestamp | |
@Column(updatable = false) | |
private Timestamp createdDate; | |
@UpdateTimestamp | |
private Timestamp lastModifiedDate; | |
public boolean isNew() { | |
return this.id == null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuperBuilder | |
@Getter | |
@Setter | |
@NoArgsConstructor | |
@AllArgsConstructor | |
public class BaseItem { | |
@JsonProperty("id") | |
private UUID id = null; | |
@JsonProperty("version") | |
private Integer version = null; | |
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ssZ", shape=JsonFormat.Shape.STRING) | |
@JsonProperty("createdDate") | |
private OffsetDateTime createdDate = null; | |
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ssZ", shape=JsonFormat.Shape.STRING) | |
@JsonProperty("lastModifiedDate") | |
private OffsetDateTime lastModifiedDate = null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuperBuilder | |
@Getter | |
@Setter | |
@NoArgsConstructor | |
@Entity | |
public class Customer extends BaseEntity { | |
private String customerName; | |
@Column(length = 36, columnDefinition = "varchar") | |
private UUID apiKey; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuperBuilder | |
@Data | |
@NoArgsConstructor | |
@EqualsAndHashCode(callSuper = true) | |
public class CustomerDto extends BaseItem { | |
private String name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment