-->
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: Column value should be the same as the other column (seq.id)
PostPosted: Tue May 28, 2013 2:38 pm 
Newbie

Joined: Thu Mar 15, 2007 10:11 am
Posts: 19
Location: Dallas
Hibernate version: Hibernate ORM 4.2.1

Here's the scenario. There are two fields in object "Product".

1) "id" is the product id and it is a oracle sequence.
2) "userGeneratedProductId" is user generated product id, if user populates it which creating the "Product" object, it should be persisted with that value. If user doesn't populate it, it should be the same value as product id "id". (At the time of persisting the product object we don't have id populated yet, and yes, we don't want to update the object with the field set after retrieving the inserted product)

How do we achieve this, does hibernate provide a way to have a field which is replica of an id filed if its not populated in the object. Does it provide interceptor calls after getting the next value on the sequence and before generating the insert statement.

Below is the sniplet of variables defined in the "Product" class.

Code:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_sequence")
@Column(name = "PRODUCT_ID")
protected Long id;


Code:
@Column(name = "USER_GENERATED_PRODUCT_ID")
    protected String userGeneratedProductId;


Here's is how we persist the prduct object.

Code:
em.persist(product);


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.