Hej
Chciałem zbudować taki model w którym podczas tworzenia Entity User powstawałaby również inne Entity Address które byłoby w relacji OneToMany.
Czytałem że można to zrobić poprzez CascadeType.PERSIST ale coś mi nie wychodzi :( Podczas tworzenia obiektu User w bazie nie tworzy się wpis w tabeli Loan.
Może przedstawię jak to robię:
Entity User:
@Entity
@Table(name="USERS")
public class User extends AbstractModel{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="USER_ID")
private long userId;
@OneToMany(mappedBy="createdBy", fetch=FetchType.LAZY, cascade=CascadeType.PERSIST)
private Set<Address> loans = new HashSet<Address>();
oraz Entity Address:
@Entity
@Table(name = "ADDRESS")
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ADDRESS_ID")
private long addressId;
@ManyToOne(cascade=CascadeType.PERSIST)
@JoinColumn(name="CREATED_BY_ID")
private User createdBy;
Gdy zapisuję Entity User niestety Address się nie zapisuje :/
Może ktoś poradzi?:)