<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How do SQL Updates to Base Tables in UpgradeProcesses work with Hibernate</title>
  <link rel="self" href="https://liferay.dev/fr/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121684693" />
  <subtitle>How do SQL Updates to Base Tables in UpgradeProcesses work with Hibernate</subtitle>
  <id>https://liferay.dev/fr/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121684693</id>
  <updated>2026-04-25T16:51:02Z</updated>
  <dc:date>2026-04-25T16:51:02Z</dc:date>
  <entry>
    <title>How do SQL Updates to Base Tables in UpgradeProcesses work with Hibernate</title>
    <link rel="alternate" href="https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121684692" />
    <author>
      <name>Adam Steiner</name>
    </author>
    <id>https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121684692</id>
    <updated>2023-03-31T18:49:05Z</updated>
    <published>2023-03-31T17:11:08Z</published>
    <summary type="html">&lt;p&gt;There are Upgrade Processes available that make performing crucial,
  non-trivial actions easier, like changing a Portlet's Id (ex:
  upgrading from 6.2 to 7.x), or updating Portlet Preferences.&lt;/p&gt;
&lt;p&gt;These Upgrade Processes, like many others, work using SQL Updates.&lt;/p&gt;
&lt;p&gt;See &lt;a
  href="https://github.com/liferay/liferay-portal/blob/29b73b9b896c7d44fb5d1800a402698c303d1cf6/portal-kernel/src/com/liferay/portal/kernel/upgrade/BaseUpgradePortletId.java#L320"&gt;https://github.com/liferay/liferay-portal/blob/29b73b9b896c7d44fb5d1800a402698c303d1cf6/portal-kernel/src/com/liferay/portal/kernel/upgrade/BaseUpgradePortletId.java#L320&lt;/a&gt;
  and &lt;a href="https://github.com/liferay/liferay-portal/blob/29b73b9b896c7d44fb5d1800a402698c303d1cf6/portal-kernel/src/com/liferay/portal/kernel/upgrade/BaseUpgradePortletPreferences.java#L205"&gt;https://github.com/liferay/liferay-portal/blob/29b73b9b896c7d44fb5d1800a402698c303d1cf6/portal-kernel/src/com/liferay/portal/kernel/upgrade/BaseUpgradePortletPreferences.java#L205&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This point goes against one of the most important rules of Liferay
  Development: &lt;em&gt;Always use the Service Layer / Model Objects /
    Hibernate to persist; Never update the database directly *&lt;/em&gt;
  &lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;​​​​​Now every rule has exceptions, and the use of SQL to make the
  staggering number of changes to needed to Upgrade from 6 to 7 makes
  perfect sense.  I suspect that the Upgrade Tool makes this easier by
  running the Server in a &amp;quot;special&amp;quot; mode, where Hibernate is
  disabled or runs differently (among other things).&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;But what about Upgrade Processes that update Base Liferay Tables
  during normal Server use, like with custom Bundles?&lt;/p&gt;
&lt;p&gt;For example: Say I have an Upgrade Step that extends
  &lt;em&gt;BaseUpgradePortletId&lt;/em&gt; to convert a 6.2 Portlet to 7.3:&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;registry.register( &amp;quot;0.0.0&amp;quot;, &amp;quot;0.0.1&amp;quot;,
    new BaseUpgradePortletId() {
        protected String[][] getRenamePortletIdsArray() {
            return new String[][] {
                {&amp;quot;myportlet_WAR_myportletplugin&amp;quot;, MyPortletKeys.MyPortlet}
            };
        }
    }
);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When it fires and makes changes to heavily used base tables (like
  &lt;em&gt;Layout&lt;/em&gt;, &lt;em&gt;PortalPreference&lt;/em&gt;,
  &lt;em&gt;ResourcePermission&lt;/em&gt;, etc) with SQL, presumably any cached
  Model Objects are now out of sync, and if those cached Objects are
  ever persisted, the SQL-induced changes will be lost.&lt;/p&gt;
&lt;p&gt;So my question is: &lt;strong&gt;How do SQL changes like these not conflict
    with cached Model Objects / Hibernate? Or, are conflicts being
    introduced, and that my team has been fortunate enough to not
    encounter them?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;(This is a question that's been nagging at me for a couple years now.)&lt;/p&gt;
&lt;p&gt;
  &lt;em&gt;*unless you know what you are doing.&lt;/em&gt;&lt;/p&gt;</summary>
    <dc:creator>Adam Steiner</dc:creator>
    <dc:date>2023-03-31T17:11:08Z</dc:date>
  </entry>
</feed>
