实际上,我正在寻找为Web服务之一设计数据模型的最佳方法。我有三个级别的关系。目前无法使用以下数据模型执行数据库操作。
Track具有一个或多个Transition Set和每个Transition Set,其中包含一个或多个转换元数据详细信息。
我制作了如下数据模型。我希望我能正确开发数据模型。
- Track
- ID
- Title
- Artist
- [Other detail fields]
- Transition Set
- ID
- Track ID
- Transition Metadata
- ID
- Transition Set ID
- [Other detail Fields]
实现了这一点,但遇到了有关数据库操作的问题,只获得了第一次转换。
@Entity
@Table(name = "tracks")
public class Track
{
@Id
@SequenceGenerator(name = "trackSeq", sequenceName = "seq_tracks_id", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "trackSeq")
private long id;
// Other fields
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = TransitionMetadata.class)
@JsonProperty
@JoinTable(name = "transition_set", joinColumns = { @JoinColumn(name = "track_id", referencedColumnName = "id",
table = "tracks") }, inverseJoinColumns = @JoinColumn(name = "id", referencedColumnName = "transition_set_id",
table = "transition_metadata"))
private List<TransitionMetadata> transitions = new ArrayList<>();
}
@Entity
@Table(name = "transition_set")
public class TransitionSet
{
@Id
@SequenceGenerator(name = "transitionSetSeq", sequenceName = "seq_transition_set_id", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "transitionSetSeq")
private long id;
@ManyToOne(cascade = CascadeType.DETACH, optional = true, fetch = FetchType.LAZY)
@JoinColumn(name = "track_id", referencedColumnName = "id")
private Track track;
}
@Entity
@Table(name = "transition_metadata")
public class TransitionMetadata
{
@Id
@SequenceGenerator(name = "transitionMetadataSeq", sequenceName = "seq_transition_metadata_id", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "transitionMetadataSeq")
private long id;
@ManyToOne(fetch = FetchType.EAGER, optional = false, cascade = CascadeType.DETACH)
@JoinColumn(name = "transition_set_id", referencedColumnName = "id")
private TransitionSet transitionSet;
// Other fields
}
看起来我被困在这里,你能不能帮我找出东西。