Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:11:12+00:00 2026-06-03T06:11:12+00:00

I have the code: @Id @Column(name = id) @GeneratedValue private int id; @Formula(value =

  • 0

I have the code:

@Id
@Column(name = "id")
@GeneratedValue
private int id;

@Formula(value = "(SELECT count(history.city_id) FROM history where history.ts > (now() - INTERVAL 30 DAY) and history.city_id = id)")
private int last30daysUpdates;

so, hiberante parse this formula to:

 ...where
            history.ts > (
                now() - entitycity0_.INTERVAL 30 entitycity0_.DAY
            ) ...

and the error is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’30 entitycity0_.DAY)

How can i say hibernate that INTERVAL and DAY are the functions of MysqL? Is it possible?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:11:13+00:00Added an answer on June 3, 2026 at 6:11 am

    Which MySQL dialect are you use?
    If MySqlDialect oder MySql5Dialect you can use follows:

    SELECT count(history.city_id) FROM history where timediff(now(), history.ts) < '720' and history.city_id = id
    

    Or define new hibernate function

    public class ExtendedMySQL5Dialect extends MySQL5Dialect 
    {
            public ExtendedMySQL5Dialect() 
            {
               super();
               registerFunction( "date_sub_interval", new SQLFunctionTemplate( Hibernate.DATE, "date_sub(?1, INTERVAL ?2 ?3)" ) );
               registerFunction( "date_add_interval", new SQLFunctionTemplate( Hibernate.DATE, "date_add(?1, INTERVAL ?2 ?3)" ) );           
            }
    }
    

    Query:

    History.ts < date_sub_interval(now(), 30, DAY)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code: <display:table name=sessionScope.allUserslist id=userList export=false pagesize=1> <display:column title=Select style=width: 90px;> <input type=checkbox
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have this code: @Column(name = foo) @ReadTransformer(transformerClass=transformer.class) private Date foo; public static class
I have a table with column for storing product code. | product_id | Product-name
I have the following code $result = $handle->select()->from('store_details') ->where('store_details.store_id=?', $id) ->columns('store_details.store_name'); //->query(ZEND_DB::FETCH_OBJ); However, when
I have this code: select a.id as tableid, a.name as tableName, b.name as columnName,
Let's assume I have defined the following Entity: @Entity class User{ @Id @GeneratedValue @Column(name
I have a DGV with columns code and name. Depends of lenght of a
I have code like following: switch(sort.Column) { case code: model = (sort.Direction == SortDirection.Ascending)
I have some PHP code which allows me to sort a column into ascending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.