How do I make a Onetomany Unidirectional relationship with joincolumn mandatory?

Asked

Viewed 486 times

1

How do I make this relationship mandatory when the in persist.() be executed?

I don’t want to map bidirectional.

@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name = "cliente_id",referencedColumnName="ID",insertable=true, nullable=false, columnDefinition="bigint DEFAULT 1 NOT NULL")
public List<Telefone> getTelefones() {
    return telefones;
}

1 answer

1

This question does not contain the Entities. Well, in this case just don’t create any attribute in the Phone class. As it is in your code, you are saying that this class (not specified in the question) has several phones. As it stands, it is already unidirectional if you have not declared any attribute of this class (not specified in the question) in the Phone class.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.