I have something strange happening on my project. I have a Bean with 2 methods. Both, do a query, on the same entity, use the same view, and only change the condition of the search, and then iterate over a collection to call another service. This 2 methods are called from 2 different scheduled tasks.
First method, works perfectly without problems, returns the record of the table, and iterate over tokens, but second, once get the record from table, get the error on the title when trying to getTokens() to iterate over it. I know this error comes from a property not added to the view, but can’t understand where is the problem here, because as I said, not only is the same entity and same view, it’s the same code BTW.
Some idea?
First method:
@Override
public void procesarNotificacionesMensajesNuevos() {
NotificacionesService servicio = AppBeans.get(NotificacionesService.class);
LoadContext<NotificacionesPool> loadContext = LoadContext.create(NotificacionesPool.class)
.setQuery(LoadContext.createQuery("Select e from project_NotificacionesPool e where e.tipoNotificacion = :tipo and e.procesado is null")
.setParameter("tipo", TipoNotificacionPool.CHAT_NUEVOS))
.setView("notificacionesPool-view");
List<NotificacionesPool> lista = dataManager.loadList(loadContext);
for(NotificacionesPool noti: lista){
for(FirebaseToken token: noti.getDestino().getTokens()) {
servicio.enviar(token.getToken(),"CHAT", "Tienes mensajes sin leer.");
}
noti.setProcesado(new Date());
dataManager.commit(noti);
}
}
Second method
@Override
public void procesarNotificacionesDeCompra() {
NotificacionesService servicio = AppBeans.get(NotificacionesService.class);
LoadContext<NotificacionesPool> loadContext = LoadContext.create(NotificacionesPool.class)
.setQuery(LoadContext.createQuery("Select e from project_NotificacionesPool e where e.tipoNotificacion = :tipo and e.procesado is null and e.anuncio is not null")
.setParameter("tipo", TipoNotificacionPool.ARTICULO_COMPRADO))
.setView("notificacionesPool-view");
List<NotificacionesPool> lista = dataManager.loadList(loadContext);
for(NotificacionesPool noti: lista){
for(FirebaseToken token: noti.getDestino().getTokens()) {
String mensaje = "Su artículo ".concat(noti.getAnuncio().getDescripcion()).concat(" ha sido comprado.");
servicio.enviar(token.getToken(),"Anuncio", mensaje );
}
noti.setProcesado(new Date());
dataManager.commit(noti);
}
}