Hello! I'm sorry for the very late answer.

On Mon, Aug 16, 2021 at 11:29 AM Vangel V. Ajanovski <ajanov...@gmail.com>
wrote:

> I'm experiencing some issue where session.createQuery always returns a
> null in the constructor of a SessionState object, after moving to 5.7.3.
> Otherwise everything works and is a welcome upgrade.
> Are there any differences in how and when Tapestry creates the hibernate
> session and how this behaves after this upgrade?
>

No. The only difference is how tapestry-hibernate gets the list of entity
classes from Hibernate. No changes were done to Tapestry-IoC of
tapestry-core that could have affected dependency injection. Maybe some
change in Hibernate itself? You should be able to use tapestry-hibernate
and tapestry-hibernate-core 5.7.2 with Tapestry 5.7.3 without issues.

To be honest, I've never had anything injected into a @SessionState object
and that's something I'd avoid doing anyway. I consider @SessionState
object to be a data storage and prefer to keep any kind of logic, specially
querying, in services.

If you want to tell Tapestry how to build and initialize your @SessionState
objects, you can implement ApplicationStateCreator and contribute an
ApplicationStateContribution instance with it for a given class to the
distributed configuration of the ApplicationStateManager services. Your
ApplicationStateCreator implementation will be called by
ApplicationStateManagerImpl to get the object instead of using
ObjectLocator.autobuild(). This is probably the best way of implementing
the logic you want here.

Please let me know if you have further questions.


>
>
> More details:
>
> I have a @SessionState UserInfo in each page where the authenticated
> user details are needed.
>
> The UserInfo class constructor calls a PersonManager service to find the
> logged-in user details.
>
> Authentication is external so it is not part of the problem. Apereo CAS,
> over all paths of the server, so that request.remoteUser contains the
> loggedin user name.
>
> In this personManager i have @Inject Session session and i have
> session.createQuery.
>
> Now the strange change in behaviour is that after upgrade to 5.7.3, all
> calls to session.CreateQuery always return null when personManager is
> called in the UserInfo constructor. Whatever query I use, it returns a
> null. As if the session is not working. But the session is not null, the
> session object status is OK and session object connection status is ok.
>
> If I call the personManager directly from a page (setupRender or
> property getter) everything works fine.
>
> Probably something is not written as it supposed to be and I need to
> refactor. Maybe we are not supposed to fill-in the UserInfo session
> state object details during its construction, but later. But this piece
> of code is more than 10 years old and has survived over all the Tapestry
> 5.x.x upgrades in the meanwhile and worked fine until now.
>
> UserInfo example:
>
> https://github.com/ajanovski/eprms/blob/main/eprms-tap/src/main/java/info/ajanovski/eprms/tap/util/UserInfo.java
>
> PersonImpl example (nothing special here):
>
> public class PersonDaoImpl implements PersonDao {
>      @Inject private Logger    logger;
>      @Inject private Session    session;
>
>      @Override
>      public List<Person> getAllPersons() {
>          try {
>              return session.createQuery("from Person order by
> lastName").list();
>          } catch (Exception e) {
>              return null;
>          }
>      }
>
>      @Override
>      public Person getPersonByUsername(String username) {
>          try {
>              return (Person) (session
>                      .createQuery("from Person where userName=:param")
>                      .setParameter("param", username).setReadOnly(true)
>                      .setCacheable(true).uniqueResult());
>          } catch (Exception e) {
>              return null;
>          }
>      }
>
> In case it matters, there is a  ComponentRequestFilter to protect access
> to pages depending on the user role, implemented like this:
>
> https://github.com/ajanovski/eprms/blob/main/eprms-tap/src/main/java/info/ajanovski/eprms/tap/services/AccessController.java
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

-- 
Thiago

Reply via email to