-->
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: Inserting Expression as a Primary Key Value,with HBM Mapping
PostPosted: Mon Mar 07, 2011 5:40 pm 
Newbie

Joined: Sun Feb 20, 2011 8:55 am
Posts: 6
I am not even sure if this is possible, my use case is as described.

I have a table, say Book, and it has a primary key say book_id which is of varchar2 type. The values for this column are of the format [F|N][0-9]*[DDMMYYYYHHMISS] format. ie. say example, F4358622032011123423 or N5358622032011123423, etc. where the first part is provided by the application (F stands for fiction, N stands for non-fiction) , middle numeric part is actually database sequence generated number and the third part is system timestamp.

I can map the middle part using the following mapping:
    <class name="Book" table="book">
    <id name="bookId" type="long" colum="book_id">
    <generator class="sequence">
    <param name="sequence">seq_book</param>
    </generator>
    </id>
    .....
    .....
    .....
    </class>

however, is there any possible way for me to delegate the creation of the entire expression(as described above) to hibernate itself. Is there a way for hibernate to evaluate an expression and add as a sequence ( for ex: say just the sequence generated number+ date timestamp)

Currently i use an utility class to generate the expression and set the returned string value to the field bookId of the Book entity. And my current mapping is as below:
    <class name="Book" table="book">
    <id name="bookId" type="string" colum="book_id" />
    .....
    .....
    .....
    </class>

I would appreciate any help regarding 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.