Remove where record field <getdate ()

I am having a hard time figuring out how to delete a recordset when a specific field is less than a date in sql server without using tables or field names.

Since I am using MSSQL, the query will look something like this:

DELETE FROM tickets WHERE expires < getdate()

      

How can I get Hibernate to do this? I am looking at HQL but don't see any way to specify getdate()

.

0


a source to share


2 answers


You should probably define a named SQL query:

<sql-query name="DeleteExpiredTickets">
 DELETE FROM tickets WHERE expires < getdate()
</sql-query>

      



Then call:

session.getNamedQuery("DeleteExpiredTickets").executeUpdate();

      

0


a source


I believe you can use the query.substitutions configuration. Take a look at this post and links in the answer:



Getting DATEPART in HQL or Criteria?

0


a source







All Articles