我想嵌入以下内容
@Embeddable
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 {
@EmbeddedId
private BaseEntity baseEntity;
@Column(length = 80, nullable = false)
private String name;
}
生成的表如下所示
room
id
createdDate
name
但是id和createddate没有嵌入
1条答案
按热度按时间wsewodh21#
而不是
@Embeddable
把你的手伸出来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;
}