【发布时间】:2017-02-08 14:59:09
【问题描述】:
我正在尝试在 Spring 数据中使用 @Embeddable 和 @Embedded。以下是我的方法。
设备实体:
@Entity
@Table(name = "device")
public class DeviceEntity implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
@AttributeOverrides({@AttributeOverride(name = "id" , column= @Column(name = "id",nullable = false))})
private DeviceIdType deviceIdType;
.
DeviceIdType:
@Embeddable
public class DeviceIdType implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
。 . .
错误信息:
"code": "4715",
"message": "Something went wrong",
"additionalInfo": "null id generated for:class com.b.DeviceEntity; nested exception is org.hibernate.id.IdentifierGenerationException: null id generated for:class com.b.DeviceEntity"
现在,当我使用 GenertionType 策略时,我得到了这个异常。
因此,我的问题是:在使用@Embeddable 和@Embedded 时如何设置GenerationType 策略?
【问题讨论】:
-
检查这是否有帮助 -> stackoverflow.com/questions/33050629/…
标签: java hibernate spring-boot spring-data-jpa