Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to insert DateTime with HQL

 
leo osst
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Im having some troubles while trying to make an insert from a select with HQL.

How can i make this in HQL

for example

insert into A (name,date1)
select p.name,to_date(<string>,<format>)
from person p

¿ Is there an equivalent "to_date" for HQL ?

Thanks in advance

leo
 
Radovan Vukovic
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this


or some other time function
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not need a function. Just use parameter binding.
 
leo osst
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys...

i'll try that.

 
leo osst
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the same problem.

Is there a way to make a date in INSERT....SELECT <here_i_want_to_make_date>
for Example
as new DateTime()
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And did parameter binding not help?
 
leo osst
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parameter binding didn't work.

I ve read that parameters binding only works in where clause.

I 've tried this

Query query = session.createQuery(insert into A (name,date1)
select p.name,:myDate
from person p )
.setParameter("myDate",myCorrectDate);

When HQL Parser tries to parse that, it shows me



It seems that :myDate is not part of select clause

Any ideas how to solve this?

Thanks

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic