Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use db2 function in the HQL

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

i am newbie to hibernate, now i am choosing a solution for my project, in this project, it use db2 function in the sql clause as follow:

insert into idstool.access(userid,node,password) values('userid','nodename',encrypt('password','nodename'));


i wonder if i can implement such function by using hibernate, that is if hibrenate can use the db2 function, or user-defined sql functions? if yes, how?


thanks for any helps
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call SQL (and vendor-specific additions to SQL) directly with Hibernate. The Sesison class has a createSQLQuery method and you can call StoredProcedures by mapping them as what is called a "named query". Whether you should is a different question, since doing this would break one of the big benefits of Hibernate: that it is portable between different RDBMSs.
[ May 31, 2006: Message edited by: Paul Sturrock ]
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
is that mean the hibrenate can call the sql clause directly(but not only the hql)? and i can embeded the db2 function into the sql clause?

i don't use stored procedure, if you can make sure it can fulfill my request, i will choose the hibrenate as the solution to my project, and i need to learn it a bit in advance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate can call SQL directly. Whether this works with inserts I'm not sure, you'll have to try it and see. That's why I mentioned stored procedures, you may have to wrap your database-specific funtions in an SP and call that instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic