For older versions of Hibernate (<5.2):
Assuming the class name is Book:
return (Number) session.createCriteria("Book")
.setProjection(Projections.rowCount())
.uniqueResult();
It is at least a Number
, most likely a Long
.
More Related Contents:
- Hibernate Annotations – Which is better, field or property access?
- What are the differences between the different saving methods in Hibernate?
- Bypass GeneratedValue in Hibernate (merge data not in db?)
- Ignore fields from Java object dynamically while sending as JSON from Spring MVC
- How should equals and hashcode be implemented when using JPA and Hibernate
- How does the FetchMode work in Spring Data JPA
- Hibernate Union alternatives
- Difference between @OneToMany and @ElementCollection?
- What is the difference between cascade & inverse in hibernate, what are they used for?
- Hibernate batch size confusion
- Transaction marked as rollback only: How do I find the cause
- JPA/Hibernate Static Metamodel Attributes not Populated — NullPointerException
- How can I use MySQL assign operator(:=) in hibernate native query?
- Hibernate: best practice to pull all lazy collections
- Do you need a database transaction for reading data?
- How to use multiple JOIN FETCH in one JPQL query
- Enum in Hibernate, persisting as an enum
- Mapping array with Hibernate
- Hibernate Annotation Placement Question
- How to create database schema in hibernate first time and further update it in case of schema modification?
- Native query with named parameter fails with “Not all named parameters have been set”
- @BatchSize a smart or stupid use?
- Spring Data JPA and Exists query
- HibernateException: Couldn’t obtain transaction-synchronized Session for current thread
- Error creating bean with name ‘entityManagerFactory
- HQL joined query to eager fetch a large number of relationships
- Clarifying terminology – What does “hydrating” a JPA or Hibernate entity mean when fetching the entity from the DB
- getting result set into DTO with native SQL Query in Hibernate
- Hibernate Issue : Foreign key must have same number of columns as referenced primary key
- How to get jdbc connection from hibernate session? [duplicate]