I am migrating from hibernate 3.5 to 5.0.3.FINAL. I am getting following error after migrated to 5. It's worked perfectly with 3.5. I am not sure what's causing this problem. "org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property".
Here is my entity classes.
Parent Entity:
@Entity @Table(name = RmbModelConstants.PRC_IMPORT_JOBS) public class ImportJob extends ComponentHistory {
public static final String SEQ_GENERATOR_NAME = "importJobsSeq"; public static final String SEQ_DB_NAME = "SEQ_PIJ";
@Id @Column(name = EntityConstants.ID) @SequenceGenerator(name = SEQ_GENERATOR_NAME, sequenceName = SEQ_DB_NAME) @GeneratedValue(strategy = GenerationType.AUTO, generator = SEQ_GENERATOR_NAME) private Long id;
@OneToOne(cascade = {CascadeType.ALL}, mappedBy = "importJob", fetch = FetchType.LAZY) private ImportData importData;
Child Entity:
@Entity @Table(name = RmbModelConstants.PRC_IMPORT_DATA)
public class ImportData {
public static final String SEQ_GENERATOR_NAME = "importDataSeq"; public static final String SEQ_DB_NAME = "SEQ_FSID";
@Id @Column(name="JOB_ID") @GeneratedValue(generator="gen") @GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="importJob")) private Long jobId;
@OneToOne @PrimaryKeyJoinColumn private ImportJob importJob;
Service Layer:
private ImportJob persistImportJob(Long libraryFeeScheduleId, String fileName, User user) { ImportJob importJob = createImportJob(fileName, user); ImportData importData = createImportData(importJob, fileStream); importData .setImportJob(importJob); importJob.setImportData(importData);
ImportJob createdImportJob = importJobJpaRepo.create(importJob); }
public ImportData createImportData(ImportJob importJob, InputStream fileStream) { ImportData importData = new ImportData(); importData.setFileName(importJob.getFileName()); importJob.setImportData(importData); importData.setImportJob(importJob); return importData; }
protected static ImportJob createImportJob(String fileName, User user) { ImportJob importJob = new ImportJob(user.getUserId()); importJob.setFileUploadedDate(DateUtils.getLocalDateTime()); importJob.setStatus(JobStatus.UPLOADED); importJob.setFileName(fileName); return importJob; }
Jpa Layer:
public ImportJob create(ImportJob importJob){ return getEntityManager().merge(importJob); }
Error: 2015-11-19T11:09:14,938 TRACE hibernate.resource.jdbc.internal.ResourceRegistryStandardImpl.releaseResources:286 - Releasing JDBC resources 2015-11-19T11:09:14,938 TRACE hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.close:220 - Logical connection closed 2015-11-19T11:09:14,938 ERROR rest.library.feeschedule.importjob.LibraryFeeScheduleImportRepresentationServiceImpl.upload:183 - Failed due to following exception javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [com.mckesson.rem.domain.model.impl.ImportData.importJob] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) ~[hibernate-entitymanager-5.0.1.Final.jar:5.0.1.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) ~[hibernate-entitymanager-5.0.1.Final.jar:5.0.1.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608) ~[hibernate-entitymanager-5.0.1.Final.jar:5.0.1.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:1171) ~[hibernate-entitymanager-5.0.1.Final.jar:5.0.1.Final] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_65] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_65] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_65] at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241) ~[spring-orm-3.2.13.RELEASE.jar:3.2.13.RELEASE] at com.sun.proxy.$Proxy75.merge(Unknown Source) ~[?:?] at com.mckesson.rem.platform.repository.impl.GenericJpaRepository.makePersist(GenericJpaRepository.java:176) ~[common-3.1.0-SNAPSHOT.jar:?] at com.mckesson.rem.domain.service.impl.ImportJobSrvcImpl.create(ImportJobSrvcImpl.java:63) ~[model-3.1.0-SNAPSHOT.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_65] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_65] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_65]
|