How to resolve org.hibernate.QueryException: could not resolve property: mobileno

594
March 13, 2017, at 12:27 PM

I am using Hibernate Criteria to get max value from column mobileno in my table.

But when I'm getting the result, it throws an exception

org.hibernate.QueryException: could not resolve property: mobileno of: 

My table bean properties is:

@Column(name="id")
private long id;
@Column(name="code")
private   String  code;

@Column(name="mobileno", updatable=true)
private   long  mobileno;
//Setters and Getters

Hibernate Code:

@Override
public long getMobile() {
    Session session = entityManager.unwrap(Session.class);
    Criteria criteria = session.createCriteria(Data.class);     
    criteria.setProjection(Projections.max("mobileno"));        
    return  (long) criteria.uniqueResult();
}

where am I going wrong, how do I get the max value from my Table???

Answer 1

You can try this:

Criteria c = session.createCriteria(Data.class);
c.addOrder(Order.desc("mobileno"));
c.setMaxResults(1);
return (Long)c.uniqueResult();

criteria.setProjection works weird

Answer 2

Try to use HQL

select max(modelName.mobileno) from ModelName 

and used setMaxResults(1).

Rent Charter Buses Company
READ ALSO
JavaFX: techniques to make Data class less verbose

JavaFX: techniques to make Data class less verbose

I'm making a simple database application with JavaFX, but I can't figure out a way of making the Data class less verbose whilst still retaining the functionality of the Add Button

503
REST Endpoint to send File in Java

REST Endpoint to send File in Java

I'm trying to write a REST API (java) that can receive a fileMy REST API looks as follows:

772
how to import CSVreader feature in my java code? For whatever reason I can't use the cvsreader feature

how to import CSVreader feature in my java code? For whatever reason I can't use the cvsreader feature

Basically I'm trying to write a converter in Java, the output will be transformed into CSV format

375
Why does if statement not execute properly? [duplicate]

Why does if statement not execute properly? [duplicate]

This question already has an answer here:

483