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 8860103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:12:14+00:00 2026-06-14T15:12:14+00:00

look likes Hibernate have not this syntax,that is right? public int MaxIdenx() { int

  • 0

look likes Hibernate have not this syntax,that is right?enter image description here

public int MaxIdenx() {
    int max = 0;
    String hql = "select ifnull(max(empId),0)from Emp";
    Query query = session.createQuery(hql);
    List currentSeq = query.list();
    if (currentSeq == null) {
        return max;
    } else {
        max = (Integer) currentSeq.get(0);
        return max + 1;
    }
}
  • 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-14T15:12:15+00:00Added an answer on June 14, 2026 at 3:12 pm

    There are a few problems with this….

    • IFNULL is COALESCE in HQL (IFNULL equivalent in Hibernate Query Language?.)
    • If you only want a single object back, use uniqueResult() instead of list().get(0).
    • HQL doesn’t have every language construct that MySQL does. It might be better to use raw SQL, with session.createSqlQuery().
    • As zerkms says, it looks like you’re managing your own sequences. Take a look at IdentifierGenerator (http://blog.anorakgirl.co.uk/2009/01/custom-hibernate-sequence-generator-for-id-field/).

    Regardless though, the code would be…

    public int MaxIdenx() {
        int max = (Integer)session
            .createQuery("SELECT COALESCE(MAX(empId), 0) FROM Emp")
            .uniqueResult();
    
        return max + 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string that look like Array that fetched from other webservice like this
Let's say I have a couple of entities that look like this: @Entity public
I have Hibernate Entities that look something like this (getters and setters left out):
When I look at Java frameworks like Hibernate, JPA, or Spring, I usually have
I have inherited a bit of Java code that uses Hibernate. Some of the
I have an RMI class that accepts remote calls from clients. This class uses
We have a Java web app with a hibernate backend that provides REST resources.
I would like to run a script indefinitely. It look likes my current script,
Because data from file look like this: line 1 is name (first last), next
It might look like a stupid question, but I recently realized that .NET implementation

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.