src/main/java/me/paulbares/service/NotificationServiceImpl.java
@Override
  @Transactional
  public void markAsRead(String userId, Collection<String> notificationIds) {
    List resultList = this.entityManager
            .createNativeQuery("SELECT r.id FROM notification n"
                    + " INNER JOIN recipient r ON n.id = r.notification_id"
                    + " WHERE r.user_id = :userId AND n.is_active = true AND r.is_read = 0 AND n.business_id IN :notificationIds")
            .setParameter("userId", userId)
            .setParameter("notificationIds", notificationIds)
            .getResultList();

    Set<Long> ids = new HashSet<>(resultList.size());
    for (Object o : resultList) {
      ids.add(((Number) o).longValue());
    }

    if (ids.size() > 0) {
      this.entityManager
              .createNativeQuery("UPDATE recipient r SET r.is_read = 1 WHERE r.id IN :ids")
              .setParameter("ids", ids)
              .executeUpdate();
    }
  }
/**
   * {@inheritDoc}
   * <p>
   * Notice that since we are using hibernate, it seems there is no generic way to update a joined table so that the
   * update is done in two steps. See this post https://stackoverflow.com/a/1293347.
   * </p>
   */

Notice that since we are using hibernate, it seems there is no generic way to update a joined table so that the
update is done in two steps.
Notice that since we are using hibernate it seems there is no generic way to update a joined table so that the update is done in two steps .
@Override
  @Transactional
  public void markAsRead(String userId, Collection<String> notificationIds) {
    List resultList = this.entityManager
            .createNativeQuery("SELECT r.id FROM notification n"
                    + " INNER JOIN recipient r ON n.id = r.notification_id"
                    + " WHERE r.user_id = :userId AND n.is_active = true AND r.is_read = 0 AND n.business_id IN :notificationIds")
            .setParameter("userId", userId)
            .setParameter("notificationIds", notificationIds)
            .getResultList();
    Set<Long> ids = new HashSet<>(resultList.size());
    for (Object o : resultList) {
      ids.add(((Number) o).longValue());
    }
    if (ids.size() > 0) {
      this.entityManager
              .createNativeQuery("UPDATE recipient r SET r.is_read = 1 WHERE r.id IN :ids")
              .setParameter("ids", ids)
              .executeUpdate();
    }
  }
@ Override @ Transactional public void markAsRead ( String userId , Collection < String > notificationIds ) { List resultList = this . entityManager . createNativeQuery ( "SELECT r.id FROM notification n" + " INNER JOIN recipient r ON n.id = r.notification_id" + " WHERE r.user_id = :userId AND n.is_active = true AND r.is_read = 0 AND n.business_id IN :notificationIds" ) . setParameter ( "userId" , userId ) . setParameter ( "notificationIds" , notificationIds ) . getResultList ( ) ; Set < Long > ids = new HashSet < > ( resultList . size ( ) ) ; for ( Object o : resultList ) { ids . add ( ( ( Number ) o ) . longValue ( ) ) ; } if ( ids . size ( ) > 0 ) { this . entityManager . createNativeQuery ( "UPDATE recipient r SET r.is_read = 1 WHERE r.id IN :ids" ) . setParameter ( "ids" , ids ) . executeUpdate ( ) ; } }
{@inheritDoc}
 <p>
 Notice that since we are using hibernate, it seems there is no generic way to update a joined table so that the
 update is done in two steps.
{ @inheritDoc } <p > Notice that since we are using hibernate it seems there is no generic way to update a joined table so that the update is done in two steps .