Java & SQL, Stronger Together


I’ve recently presented my new talk “Java & SQL — Stronger Together” as a free webinar.

The (updated) slides are available as PDF download (10MB), the recording is also available at Vimeo.

Sponsors: ProHuddle and Gitora

This webinar war organized by ProHuddle, Engaging Webinars with IT Professionals, and sponsored by Gitora, Version Control for Oracle.

Key takeaways:

  • Software layers make many tasks easier but don’t expose 100% of the lower layers functionality.

  • What is the right level of abstraction for any given problem?

  • The ORM-cycle: Load data into application, change it there, store changes.

  • Pattern #1: Whenever the cycle is broken, ORM might not be the right layer for this task. Example: Lists.

  • SQL has evolved beyond the relational idea. Recursion is an example for a non-relational operation that can traverse graphs like adjacency lists.

  • We can use native SQL to efficiently load required entities into the persistence context prior to running the actual business logic.

  • If the actual business logic needs an entity that is already in the persistence context, it doesn’t need to run a query to fetch it.

  • Pattern #2: Searching & pre-loading entities with modern SQL can be much more efficient than loading them individually when accessing them.

There are two gotchas that I didn’t mention in the talk (but now mention them in the updated slides):

  • The persistence context is usually accessed by the @Id attribute. If the business logic loads entities by other means, it will typically not be able to use the cached version in the persistence context.

    A few years back I stumbled upon this article which demos an EclipseLink feature for that (@CacheIndex).

  • Running a native query to pre-load entities triggers a flush, which might have negative side effects.

    These queries should be triggered at the very beginning of a transaction, not in the middle. Code re-use might accidentally trigger such a query in the middle of a transaction.

You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Twitter or RSS to gradually catch up and to keep modern-⁠sql.com on your radar.

About the Author

Photo of Markus Winand

Markus Winand provides insights into SQL and shows how different systems support it at modern-sql.com. Previously he made use-the-index-luke.com, which is still actively maintained. Markus can be hired as trainer, speaker and consultant via winand.at.

Buy the Book

Cover of “SQL Performance Explained”: Squirrel running on grass

The essence of SQL tuning in 200 pages

Buy now!
(paperback and/or PDF)

Paperback also available at Amazon.com.

Hire Markus

Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »

Connect with Markus Winand

Subscribe mailinglistsSubscribe the RSS feedMarkus Winand on LinkedInMarkus Winand on XINGMarkus Winand on TwitterMarkus Winand on Bluesky
Copyright 2015-2024 Markus Winand. All righs reserved.
Legal | Contact | NO WARRANTY | Trademarks | Privacy and GDPR