-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to use id as the part of other fields?
PostPosted: Fri Jan 20, 2006 11:27 pm 
Newbie

Joined: Tue Oct 25, 2005 10:49 pm
Posts: 9
Hi,

table employee (id int, departmentno int, employeeno varchar)

id is automatically generated by the DB server, I want employeeno consists of department no and id, i.e.

id 123
departmentno 777

the employeeno supposed is 777123

when I add new employee, and before I write the data into table, how can I generate the employeeno?

I am using Hibernate 3.0, struts 1.2.7, J2SDK 1.4.2, PostgreSQL 8.0

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 11:58 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
1. You can define a preInsert Event something like
Code:
    <event type="pre-insert">
        <listener class="xxx.yyy.zzz"/>
   </event>


The xx.yyy.zzz class will then implement the PreInsertEventListener. Look up Events and Intereceptors in the manual.

2. Im not sure if you can do this. But when you define the property, you can use the formulat attribute of this to do something like
Code:
<property name="employeeno" .... formula="departmentno || id" />

Im not sure if it would work but you can check out the semantics of formula to see if this is doable.


Top
 Profile  
 
 Post subject: I will try
PostPosted: Sat Jan 21, 2006 10:48 am 
Newbie

Joined: Tue Oct 25, 2005 10:49 pm
Posts: 9
Hi Rajasaur,

Thanks, I will try and see what will happen.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.