Domanda

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

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top