This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to insert DateTime with HQL  RSS feed

 
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this


or some other time function
 
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
Boost this thread!