如果没有实体,如何将数据放在表中

时间:2018-10-21 11:23:09

标签: java mysql spring hibernate spring-mvc

我有一些依赖项实体。我希望将parent_id的storage_id存储在额外的表中。但是我不知道如何执行此操作,我创建了一个辅助表,但是现在我不了解如何在创建StorageElement时为此元素设置parent_id。 最重要的是,如何获取我的parent_id进行存储。 我想我需要更改依赖关系,但是如何?

@Entity
@DiscriminatorColumn(name = "type")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class StorageElement {

@Enumerated(value = EnumType.STRING)
@Column(updatable = false, insertable = false)
private SomeType type;

@Id
@GeneratedValue
private Long id;

@Column
private String name;

@OneToOne
@JoinColumn(name = "user_id")
@JsonIgnore
private AccountEntity owner;

@Column
private Long size;

@ManyToOne(targetEntity = Organization.class)
@JoinColumn(name = "organization_id")
@JsonIgnore
private Organization organization;

@OneToMany(targetEntity = StorageElement.class)
@JsonIgnore
private List<StorageElement> children;

} {

@Entity
@DiscriminatorValue("CHANNEL")
public class Channel extends StorageElement{

@ManyToMany(cascade = CascadeType.REMOVE)
@JoinTable(
        name="channel_account",
        joinColumns=@JoinColumn(name="channel_id", 
referencedColumnName="id"),
        inverseJoinColumns=@JoinColumn(name="user_id", 
referencedColumnName="id"))
List<AccountEntity> accountEntityList;

@ManyToMany(cascade = CascadeType.REMOVE)
@JoinTable(
        name="storage_parent",
        joinColumns=@JoinColumn(name="parent_id", 
referencedColumnName="id"),
        inverseJoinColumns=@JoinColumn(name="storage_id", 
referencedColumnName="id"))
List<StorageElement> storageElementList;

}

这是我的桌子。

Table StorageElement, which consists of 4 entities, one of which is Channel; Additional table;

任何帮助将不胜感激。qd

0 个答案:

没有答案