1

I want to embed the following

 @Embeddable
  public class BaseEntity implements Serializable {

  @Id
  @GeneratedValue
  private UUID id;

  @CreatedDate
  @Column(name = "created_date", updatable = false)
  private LocalDateTime createdDate;

 }

into my room entity

    @Entity
    @Data
    @NoArgsConstructor
    @Table(name = "room")
    public class room {
    
      @EmbeddedId
      private BaseEntity baseEntity;
    
    
      @Column(length = 80, nullable = false)
      private String name;
}

So that my generated table looks like this

room
  id
  createdDate
  name

But id and createdDate are not getting embedded

Frant
  • 5,382
  • 1
  • 16
  • 22
JangoCG
  • 823
  • 10
  • 23

1 Answers1

1

Instead of @Embeddable just extend your BaseEntity

@MappedSuperclass 
@Getter
@Setter
public class BaseEntity implements Serializable {

  @Id
  @GeneratedValue
  private UUID id;

  @CreatedDate
  @Column(name = "created_date", updatable = false)
  private LocalDateTime createdDate;

 }

@Entity
@Data
@NoArgsConstructor
@Table(name = "room")
public class room extends BaseEntity{

  @Column(length = 80, nullable = false)
  private String name;

}
Aritra Paul
  • 834
  • 1
  • 8
  • 14