Hi Chris,

we ran into similar issues with custom queries, our workaround is calling
getSession() on the session, like this:

   return this.session.getSession().createQuery(sql) //
                           .setParameter("replyToId", relatedId) //
                           .setParameter("type", type) //
                           .executeUpdate();

It's ugly and the call is deprecated, but it worked for us.
We never really looked into it, though, as we usually don't use Hibernate
via named/custom queries that much.

My guess would be that something changed in the Hibernate session,
and 
org.apache.tapestry5.hibernate.modules.HibernateCoreModule.buildSession(HibernateSessionManager,
PropertyShadowBuilder) doesn't work as initially intended anymore.

Cheers
Ben

On Fri, Jun 9, 2023 at 1:43 PM Christopher Dodunski (Tapestry) <
chrisfromtapes...@christopher.net.nz> wrote:

> Hello,
>
> I've encountered an issue after upgrading from Tapestry 5.6.4 to 5.7.3.
> This included moving from Hibernate 5.1.0.Final to 5.4.32.Final (as per
> the guidelines).
>
> The HibernateCrudServiceDAO method below is now failing to fetch named
> queries via the injected org.hibernate.Session, resulting in a null
> pointer exception when attempting to write parameters to it.
>
> I'm wondering whether this might have something to do with
> org.hibernate.Query having been deprecated and replaced with
> org.hibernate.query.Query.  I understand the tapestry-hibernate package
> was reworked around the time of Tapestry 5.7.3 to support changes in
> Hibernate.
>
> Incidentally, the issue remains with Tapestry 5.8.2.
>
> Any help/insights would be much appreciated.
>
> Thanks & regards,
>
> Chris.
>
>
> import org.hibernate.query.Query;
> import org.hibernate.Session;
> ...
>      @Inject
>      private Session session;
> ...
>      public <T> T findUniqueWithNamedQuery(String queryName, Map<String,
> Object> params){
>          Set<Entry<String, Object>> rawParameters = params.entrySet();
>          Query query = session.getNamedQuery(queryName);
>
>          if(query == null) LOG.error("Oops, Hibernate session returned
> null Query object!");
>          if(query != null) LOG.debug("Query string = " +
> query.getQueryString());
>
>          for(Entry<String, Object> entry : rawParameters){
>              LOG.debug("Entry key = " + entry.getKey());
>              LOG.debug("Entry value = " + entry.getValue().toString());
>              query.setParameter(entry.getKey(), entry.getValue());
>          }
>
>          return (T) query.uniqueResult();
>      }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to