-->
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: How do I declare a Formula field generated by the database ?
PostPosted: Fri Jun 22, 2007 6:32 am 
Newbie

Joined: Wed Jun 20, 2007 7:32 am
Posts: 2
I want a DB generated value on INSERT and on UPDATE.
This value must be persisted, hence, AFAIK, formula cannot be used.
This value is, afterwards, used as a criteria for search.

Exemple :
To generate something like :

Code:
INSERT INTO employee (ename, soudexcode) VALUES ('Achille', 'SOUNDEX('Achille'));

I'd like to write something like :

Code:
@Column(name="ename")
private String name;

@Column(updatable=true, insertable=true, name="soundexcode")
@Generated(GenerationTime.ALWAYS, formula='SOUNDEX(name)')
private String soundexCode;

which may be a bit tricky because of parameter substitution.
The following proposition should be more flexible and quite simplier to implement :
Code:
@Column(updatable=true, insertable=true, name="soundexcode")
@Generated(GenerationTime.ALWAYS, formula=methodToComputeSQLStringFromThisInstance())
private String soundexCode;

with :
Code:
public String methodToComputeSQLStringFromThisInstance()
{
  return "SOUNDEX("+name+")";
}


which has no parameter substition and is quite simple !

I'd just like to generate my INSERT/UPDATE SQL statement per column, and not per table as it is possible now.
Hence, I don't have to maintain a SQL query. I still use hibernate to generate it for me.
This way, I don't have to INSERT, then SELECT, then UPDATE then re-SELECT my row in order to get a DB-computed value.
I don't want to use a database trigger where there is no need for a database trigger.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 9:07 am 
Newbie

Joined: Wed Jun 20, 2007 7:32 am
Posts: 2
Am I the only one looking for such a feature ?
Maybe the original post is incomprehensible ?


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.