Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Custom operations in HibernateDataSource

    I wish to implement business logic during data source operations. My data sources are configured with serverType="hibernate". In the data source XML configurations, I know I can specify a class name for the "serverConstructor" attribute, and within the class I can implement the various methods (executeAdd, executeFetch, executeRemove, etc). Within those methods, I can manipulate the data values passed as Maps via the DSRequest.

    But what I'd prefer to do is invoke bean methods on the underlying Hibernate-mapped classes, and also obtain a Hibernate session for conducting any further queries necessary to support the custom business logic. So, basically, I want to intercept the operation, run some business logic that operates upon Hibernate-mapped classes, and then let Hibernate complete its persistence operation.

    What is the "best practices" way of doing this within the SmartGWT framework? I am running SmartClient Version: v8.3p_2013-08-06/Pro Deployment (built 2013-08-06)

    I've looked into using Hibernate interceptors but I am unsure how to configure them to work with SmartGWT, since I am relying on SmartGWT to detect the hibernate.cfg.xml configuration in the classpath to initialize the session factory.

    Thanks for any suggestions,
    Dave

    #2
    Best practice in this case is typically to create and execute another DSRequest server-side, rather than directly use Hibernate APIs.

    This is partly because it takes thousands of lines of code to replicate what some DSRequests do with Hibernate, but also because you get more uniform server logging, and can use transaction chaining, and many other reasons.

    But in the rare case that there is something that makes sense to do directly with Hibernate APIs, you can use DataSource.getTransactionObject() to get the Hibernate session. See the docs for this method for details, and you can also take a look at this sample, which does the analogous thing but for SQL.

    Comment


      #3
      This is great - thank you for your helpful response!

      Comment

      Working...
      X