У меня есть 2 таблицы: папка (простой первичный ключ) и документ (составной первичный ключ)
Я хочу, чтобы таблица соединений с именем folder_documents, которая будет содержать идентификатор обеих таблиц с дополнительными колонкиjpa много для многих с дополнительным столбцом и составным ключом
Существует мои объекты:
Папка
@Entity
@Table(name = "folder")
public class Folder {
@Id
@SequenceGenerator(name = "folder_seq_gen", sequenceName = "FOLDER_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "folder_seq_gen")
private long id;
@Column
private Date date;
@OneToMany(mappedBy = "folder_documents_compositeKey.folder",
cascade = CascadeType.ALL)
private Set<Folder_Documents> folder_documents;
Документ
@Entity
@Table(name="document")
public class Document {
@EmbeddedId
private DocumentID documentCompositeKey;
@Column
private Date date;
DocumentID (составной ключ)
@Embeddable
public class DocumentID implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String id;
private String matricule;
Folder_Document (присоединиться к таблице)
@Entity
@Table(name = "folder_documents")
@AssociationOverrides({
@AssociationOverride(name = "folder_documents_compositeKey.folder",
joinColumns = @JoinColumn(name = "folder_id")),
@AssociationOverride(name = "folder_documents_compositeKey.document",
joinColumns = @JoinColumn(name = "doc_id" , referencedColumnName = "id")), // error mapping there
@AssociationOverride(name = "folder_documents_compositeKey.document",
joinColumns = @JoinColumn(name = "matricule" , referencedColumnName = "matricule"))})// error mapping there
public class Folder_Documents {
@EmbeddedId
private Folder_Documents_ID folder_documents_compositeKey = new Folder_Documents_ID();
@Column
private Date date;
@Column
private String status;
Folder_documents_id (составной ключ)
@Embeddable
public class Folder_Documents_ID implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@ManyToOne(cascade = CascadeType.ALL)
private Folder folder;
@ManyToOne(cascade = CascadeType.ALL)
private Document document;
Проблема в том, что я не могу сопоставить Document
compositeKey в Folder_Documents
's @AssociationOverrides
атрибутах, потому что спящий режим не находит th идентификатор составного ключа и свойства матрицы в Document
. Ссылки на папки хороши.
Существует StackTrace:
Caused by: org.hibernate.AnnotationException: referencedColumnNames(matricule) of com.renault.entity.Folder_Documents_ID.folder_documents_compositeKey.document referencing com.renault.entity.Document not mapped to a single property