Skip to content

Instantly share code, notes, and snippets.

@susimsek
Last active November 20, 2020 10:31
Show Gist options
  • Save susimsek/19a1fa97943a89dfdc70144dad14e0a1 to your computer and use it in GitHub Desktop.
Save susimsek/19a1fa97943a89dfdc70144dad14e0a1 to your computer and use it in GitHub Desktop.
Lombok Builder Extends with Jpa
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@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;
}
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
public class Customer extends BaseEntity {
private String customerName;
@Column(length = 36, columnDefinition = "varchar")
private UUID apiKey;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment