-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Migration from 3.x to 5.x
PostPosted: Thu Nov 19, 2015 2:00 pm 
Newbie

Joined: Thu Nov 12, 2015 6:45 am
Posts: 1
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]


Top
 Profile  
 
 Post subject: Re: Hibernate Migration from 3.x to 5.x
PostPosted: Fri Nov 20, 2015 5:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Jul 17, 2011 9:28 am
Posts: 4
try to set hibernate.id.new_generator_mappings=false;

if the issue persists even with this conf can you please open a thicket on JIRA https://hibernate.atlassian.net?

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.