-->
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.  [ 5 posts ] 
Author Message
 Post subject: Data base Insert problem
PostPosted: Thu Jun 21, 2007 9:57 am 
Newbie

Joined: Thu Jun 21, 2007 9:52 am
Posts: 5
HI

I am new to hibernate implementation; I did normal insertions (just simple insert queries) with hibernate successfully. I struck up with a problem where I need to insert data with sub query (dynamic).

Query is:
INSERT INTO "CREDIT_CARD" (CNUMBER,CTYPE, EXPDATE,CUID,LAST_UPDATE) VALUES ((select tcrypt.tencrypt('234509873333') from dual),'AMEX','060627',43903873,sysdate);

Here my question is how can I execute “select tcrypt.tencrypt('234509873333') from dual” which is inside a Query.

I did one way is that, writing this as Native SQL and insert into data base.

Please suggest is there any alternative to execute the above query.

Thanks in advance
[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 10:24 am 
Beginner
Beginner

Joined: Wed Sep 06, 2006 12:08 pm
Posts: 48
Location: Warsaw - Poland - Europe - Milky Way
Hello

Have a look here: http://www.hibernate.org/hib_docs/v3/reference/en/html_single/index.html#mapping-column

And have a look at:
Code:
default="SQL expression"


Maybe this is what you are looking for.

Regards!
Adam

PS.
Rate if this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 10:55 am 
Newbie

Joined: Thu Jun 21, 2007 9:52 am
Posts: 5
Hi Adam,
Thanks for you reply,
I tried like below in the mapping file and it is not succeeded
<property name="card_number" formula="(select tcrypt.tencrypt(card_number) from dual)" >
<column name="CNUMBER"/>
</property>

If I wrongly understood please let me know

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Data base Insert problem
PostPosted: Thu Jun 21, 2007 10:57 am 
Newbie

Joined: Tue Apr 10, 2007 10:40 am
Posts: 8
Try removing the VALUES clause:

Code:
INSERT INTO "CREDIT_CARD" (CNUMBER,CTYPE, EXPDATE,CUID,LAST_UPDATE) select tcrypt.tencrypt('234509873333'),'AMEX','060627',43903873,sysdate from dual


Also note that when using HQL the VALUES clause isn't supported. Quoting from http://www.hibernate.org/hib_docs/v3/re ... tch-direct

Quote:
Only the INSERT INTO ... SELECT ... form is supported; not the INSERT INTO ... VALUES ... form.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 12:01 pm 
Newbie

Joined: Thu Jun 21, 2007 9:52 am
Posts: 5
Hi gwiley,
Thanks for your reply,
Can we do the same functionality using Hibernate mapping file i.e Object level.
Thanks in advance


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