У меня есть две таблицы:
И я пытаюсь сопоставить их с JPA / Hibernate следующим образом: ENTITY:
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "global_task_dependency")
public class GlobalTaskDependency implements Serializable {
private static final long serialVersionUID = 1901782042815898352L;
@EmbeddedId
private GlobalTaskDependencyPK id;
}
PK:
@Data
@AllArgsConstructor
@NoArgsConstructor
@Embeddable
public class GlobalTaskDependencyPK implements Serializable {
private static final long serialVersionUID = -2939678921007532701L;
@ManyToOne
@JoinColumn(name = "global_task_id")
private Task globalTask;
@ManyToOne
@JoinColumn(name = "parent_task_id")
private Task parentTask;
@ManyToOne
@JoinColumn(name = "child_task_id")
private Task childTask;
}
ИСКЛЮЧЕНИЕ:
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1499)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1422)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:360)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:382)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:371)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 97 more
Каждый раз, когда я получал NullPointerExeption при попытке запустить приложение.Когда я заменяю Task
поля его реальным идентификатором, который Long
, он работает нормально, но я теряю @ManyToOne
отношений.
Любой совет, как правильно сопоставить?
UPD:ЗАДАЧА ЛИЦА:
@Data
@Entity
@Table(name = TASK_TABLE)
@Inheritance(strategy = InheritanceType.JOINED)
public class Task implements Serializable {
private static final long serialVersionUID = 8412873233077674082L;
@Id
@GeneratedValue
private Long id;
@Version
private int version = 1;
@Column(name = "taskstatus_id")
private TaskStatus taskStatus;
@ManyToOne
@JoinColumn(name = "tasktype_id")
private TaskType taskType;
@Column(name = "creation_date")
private Date creationDate;
}