Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the ability to work with the database MySql #2

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
edit repo allPlayer
  • Loading branch information
sfill70 committed Dec 26, 2022
commit dbc1124f7985b193e5389a145e7cd4abacfc51d6
3 changes: 2 additions & 1 deletion src/main/java/com/game/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import java.util.Date;


@NamedQuery(name = "getAllCount",
query = "SELECT COUNT(*) FROM Player")
@Entity
@Table(name = "player", schema = "rpg")
public class Player {
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/game/repository/PlayerRepositoryDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ public List<Player> getAll(int pageNumber, int pageSize) {
@Override
public int getAllCount() {
try (Session session = sessionFactory.openSession()) {
//Это не работает.
/* Query<Integer> query = session.createQuery("select count (*) from Player",Integer.class);
return query.uniqueResult();*/
Query allPlayersCount = session.createQuery("from Player");
return allPlayersCount.list().size();
// Query<Long> query = session.createQuery("select count (*) from Player", Long.class);
Query<Long> query = session.createNamedQuery("getAllCount",Long.class);
return Math.toIntExact(query.uniqueResult());
}

}
Expand Down