GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes How to insert DateTime with HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to insert DateTime with HQL" Watch "How to insert DateTime with HQL" New topic
Author

How to insert DateTime with HQL

leo osst
Greenhorn

Joined: Nov 10, 2010
Posts: 4
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

Joined: Nov 03, 2010
Posts: 19
Try something like this


or some other time function
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You should not need a function. Just use parameter binding.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
leo osst
Greenhorn

Joined: Nov 10, 2010
Posts: 4
thanks guys...

i'll try that.

leo osst
Greenhorn

Joined: Nov 10, 2010
Posts: 4
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

Joined: Apr 14, 2004
Posts: 10336

And did parameter binding not help?
leo osst
Greenhorn

Joined: Nov 10, 2010
Posts: 4
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

 
Consider Paul's rocket mass heater.
 
subject: How to insert DateTime with HQL