Пример #1
0
  public void removePlayerFromLeague(League league, Player player) {
    //		List<PlayerLeague> playerLeagues = hibernateTemplate.find(getPlayerLeagueQuery("", "where
    // playerleague.player.id=? and playerleague.league.id=?"),
    //				new Object[] {player.getId(), league.getId()});
    //		if (!playerLeagues.isEmpty())
    //		{
    //		 hibernateTemplate.delete(playerLeagues.iterator().next());
    //		}
    //		if (!playerLeagues.isEmpty())
    //		{
    //			dao.delete(playerLeagues.iterator().next());
    //		}

    Query query =
        getQuery(
            getPlayerLeagueQuery(
                "", "where playerleague.player.id=? and playerleague.league.id=?"));
    query.setParameter(0, player.getId());
    query.setParameter(1, league.getId());

    List<PlayerLeague> playerLeagues = query.list();

    for (PlayerLeague playerLeague : playerLeagues) {
      Query query2 = getQuery("delete from playerLeague where id = ?");
      query2.setParameter(0, playerLeague.getId());

      query2.executeUpdate();
    }
  }
Пример #2
0
  public int findNumberOfPlayersInLeague(final League league) {

    //		  return (Integer) getHibernateTemplate().execute(new HibernateCallback() {
    //			   public Object doInHibernate(Session session) throws HibernateException, SQLException {
    //				   Query query = session.createQuery("select count(playerleague.player) from PlayerLeague
    // playerleague where playerleague.league.id=?").setLong(0, league.getId());
    ////					"select count(playerleague.player) from PlayerLeague playerleague where
    // playerleague.league.id=?").setLong(0, league.getId());
    //					return Integer.parseInt(""+query.iterate().next());
    //				   }
    //				  });

    Query query =
        getQuery(
            "select count(playerleague.player) from PlayerLeague playerleague where playerleague.league.id=?");
    query.setParameter(0, league.getId());

    int num = Integer.parseInt("" + query.iterate().next());
    return num;
  }