문제

I'm new with hibernate and JPA, and I'm trying to do the next thing:

public class Centre extends JpaStandardVersionableEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sq")
@SequenceGenerator(name = "sq", sequenceName = SQ_NAME)
@Column(name = "ID_CTR", nullable = false)
private Integer idCtr;
        ...

@JoinColumn(name = "ID_DRC", referencedColumnName = "ID_DRC", nullable = false)
@ManyToOne(cascade = CascadeType.ALL, optional = false, fetch = FetchType.LAZY)
private Address idDrc;

}


public class Address extends JpaStandardVersionableEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sq")
@SequenceGenerator(name = "sq", sequenceName = SQ_NAME)
@Column(name = "ID_DRC", nullable = false)
private Integer idDrc;
}

With the cascade ALL in order to insert an address when I'm registering a Centre.

But I'm having this error: integrity constraint FK_CTR_DRC violated - parent key not found

Seems this is not working as expected... Any ideas? Thanks in advance

도움이 되었습니까?

해결책

The snippet is correct. My problem was actually related to the Address trigger. Apologize for the incovenience.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top