gpt4 book ai didi

java - 在EmbeddedId中使用@JoinColumn会生成org.hibernate.MappingException

转载 作者:行者123 更新时间:2023-11-30 02:34:05 26 4
gpt4 key购买 nike

我有一个带有复合 ID 的表,其中一个字段是另一个表的外键。

enter image description here

我尝试使用以下类来实现这一点 -

Tracking.java:

public class Tracking {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long trackingId;
private String accountNumber;
private TrackingType trackingType;
}

TrackingUseCaseDetails.java

public class UseCaseStatus implements Serializable {

private static final long serialVersionUID = -7058248210575975131L;

@EmbeddedId
private ID id;
private String status;
private String resourceId;
}

ID.java

public class UseCaseStatusId implements Serializable {

private static final long serialVersionUID = -7037374226692973832L;

@JoinColumn(name = "trackingId", updatable = false, nullable = false)
private Tracking tracking;
private TrackingUseCase trackingUseCase;
}

但是我收到以下错误:

org.hibernate.MappingException: Could not determine type for: Tracking, at table: TrackingUseCaseDetails, for columns: [org.hibernate.mapping.Column(tracking)]

关于如何解决错误/改进代码有什么建议吗?

最佳答案

试试这个:

@Entity
public class UseCaseStatus implements Serializable {

@EmbeddedId
private UseCaseStatusId id;

@MapsId("tracking")
@ManyToOne
@JoinColumn(name = "trackingId", updatable = false, nullable = false)
private Tracking tracking;

private String resourceId;
}


@Embeddable
public class UseCaseStatusId implements Serializable {

//@JoinColumn(name = "trackingId", updatable = false, nullable = false) <- prob not required
private long tracking;

@Column(name = "status")
private String status;

//implement equals() and hashcode() : https://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Embedded_Id
}

关于java - 在EmbeddedId中使用@JoinColumn会生成org.hibernate.MappingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43545957/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com