Answer the question
In order to leave comments, you need to log in
Hibernate ManyToOne relationship not by primary key?
Hello everyone, I just started to study Hibernate, I have one question.
In all examples, the connection of objects (ManyToOne and OneToMany) occurs according to the primary key, usually long ID, I found on the Internet that uuid can also be the primary key.
Actually a question:
long id; //This is the primary key
UUID guid; // how to bind a set by this key without making it primary?
@Entity
public class Dictionary {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column
UUID guid = UUID.randomUUID(); //Как привязать DictionaryContent к этому идентификатору, не делая его первичным ключом?
@OneToMany(cascade = CascadeType.ALL,orphanRemoval = true)
@JoinColumn(name = "dictionary_id")
private List<DictionaryContent> contentList;
}
@Entity
public class DictionaryContent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
UUID guid = UUID.randomUUID();
@ManyToOne
private Dictionary dictionary;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question