-->
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.  [ 1 post ] 
Author Message
 Post subject: Custom Hib sequence for Composite key(save not working)
PostPosted: Tue Jun 14, 2016 1:59 am 
Newbie

Joined: Tue Jun 14, 2016 1:36 am
Posts: 1
I have a composite key in one of my persistence class ProductVersionElement for id and versionid. For each key, i have a custom hibernate sequencer as IdGenerator and VersionIdGenerator.

Code:
       
        @Id
   @GenericGenerator(name = "custom_id", strategy = "com.model.persistent.sequencer.IdGenerator")
   @GeneratedValue(generator = "custom_id")
   protected String id;
   
   @Id
   @GenericGenerator(name = "custom_versionId", strategy = "com.model.persistent.sequencer.VersionIDGenerator")
   @GeneratedValue(generator = "custom_versionId")
   protected String versionId;


Case 1. When both the id and versionid are null. Then the sequencer populates the sequence for both fields and successfully save the ProductVersionElement. After the save, in debug it shows the generated values for both fields.

Case 2: When the id is set(i know the value beforehand and only want to generate the versionid) and versionid is null. For this i have changed the sequencer such that : if the value of field is null, then generate the sequence else return the same value.

Code:
if (id == null) {
   //Generate the sequence and return
} else{
  // return same id
}


In this case, it is not saving the ProductVersionElement. Even after the save , it is only showing the value of id(that was already set) and versionid is still null after save.

Although it does not result in any exception and after that when i try to save one other Object : ProductCharacteristics which contains ProductVersionElement(to save one of its id), it is resulting in the following error:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.orange.obsit.sando.cibinternational.model.persistent.ProductCharacteristic.productVersionElement -> com.orange.obsit.sando.cibinternational.model.persistent.ProductVersionElement;

Could you please give any suggestions on this?


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

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.