Jpa 2.0 - EntityManager.find (SomeEntity.class, PK) need to fill Discriminator value with key
I have a problem, I have two Job and JobPK objects
Job class looks like this sample code :
@Entity
@IdClass(JobPK.class)
@Table(name="JOB")
@Inheritance
@DiscriminatorColumn(name="JOB_TYPE")
public abstract class Job implements Serializable {
@Id
@Column(name="FOLDER_ID")
private BigDecimal folderId;
@Id
@ColumnDefinition(position = 1)
private String name;
@Column(name="JOB_TYPE",insertable=false,updatable=false)
private String jobType;
...
}
and JobPk:
public class JobPK implements Serializable {
private static final long serialVersionUID = -3266336718203527905L;
@Column(name="JOB_TYPE",insertable=false,updatable=false)
private String jobType;
@Id
private String name;
@Id
@Column(name="FOLDER_ID")
private BigDecimal folderId;
......
}
I have two classes that extend Job: CalculatingJob and ImportingJob Now I will not use:
getEntityManager().find(CalculatingJob.class, new JobPK (BigDecimal.valueOf(folderId),name))
and I have a problem because I have to fill in the JobPK parameter value field. If I don't, I have a Null Pointer exception. The default Discriminator value is key, I think, but I don't want the delimiter value information to be called during JobPk creation. I thought that an Entity that extends from Job would auto-populate this field. Any idea to work around this issue, maybe I can get Annotation @DescriminatorVale from CalculateJob and then put into JobPk constructor
thanks for the help
source to share
Try this configuration for hierarchy structure
Job.java
@Table(name = "JOB")
@Inheritance
@IdClass(JobPK.class)
@DiscriminatorColumn(name = "JOB_TYPE", discriminatorType = DiscriminatorType.STRING)
public abstract class Job implements java.io.Serializable {
}
CalculatingJob.java
@Entity
@DiscriminatorValue("CalculatingJob")
public class CalculatingJob extends Job {
}
ImportingJob.java
@Entity
@DiscriminatorValue("ImportingJob")
public class ImportingJob extends Job {
}
JobPK.java
public class JobPK implements Serializable {
}
The discriminator value is entered by sleep mode.
source to share