Код: Выделить всё
@Table(name = "input")
@Entity
@Data
public class CreationInputEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "ID", unique = true, nullable = false, updatable = false)
Long id;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "index_id", referencedColumnName = "id")
IndexEntity index;
}
@Table(name = "index")
@Entity
@Data
public class IndexEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", unique = true, nullable = false, updatable = false)
Long id;
@OneToOne(mappedBy = "index")
CreationInputEntity creationInputEntity;
@NotBlank
@Column(name = "indexName")
String indexName;
@OneToMany(mappedBy = "index", cascade=CascadeType.ALL)
List indexshares;
}
@Entity
@Data
public class IndexshareEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "ID", unique = true, nullable = false, updatable = false)
public Long id;
....
@ManyToOne
@JoinColumn(name="index_id")
public IndexEntity index;
}
Код: Выделить всё
CreationInputEntity createdCreationInputEntity = inputRepository.saveAndFlush(creationInputEntity);
Заранее спасибо за помощь.
Подробнее здесь: https://stackoverflow.com/questions/791 ... st-and-sav