<?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>Is _applyMaxStringIndexLengthLimitation() method implemented correctly??</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121161463" />
  <subtitle>Is _applyMaxStringIndexLengthLimitation() method implemented correctly??</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121161463</id>
  <updated>2026-06-12T15:51:11Z</updated>
  <dc:date>2026-06-12T15:51:11Z</dc:date>
  <entry>
    <title>Is _applyMaxStringIndexLengthLimitation() method implemented correctly??</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121161462" />
    <author>
      <name>Rupal Chatterjee</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121161462</id>
    <updated>2021-10-04T17:03:56Z</updated>
    <published>2021-09-22T10:15:09Z</published>
    <summary type="html">&lt;p&gt;Hello Everyone,&lt;/p&gt;
&lt;p&gt;I was going through the source code of Liferay libraries to find out
  the root cause of the issue, I faced during upgradation of our Liferay
  version from 7.2 to 7.3. Finally I came across
  this _applyMaxStringIndexLengthLimitation(String template) method
  implemented in com.liferay.portal.dao.db.BaseDB abstract class.&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;private String _applyMaxStringIndexLengthLimitation(String template) {
    if (!template.contains(&amp;quot;[$COLUMN_LENGTH:&amp;quot;))
      return template; 
    DBType dbType = getDBType();
    int stringIndexMaxLength = GetterUtil.getInteger(PropsUtil.get(&amp;quot;database.string.index.max.length&amp;quot;, new Filter(dbType.getName())), -1);
    Matcher matcher = _columnLengthPattern.matcher(template);
    if (stringIndexMaxLength &amp;lt; 0)
      return matcher.replaceAll(&amp;quot;&amp;quot;); 
    StringBuffer sb = new StringBuffer();
    String replacement = &amp;quot;\\(&amp;quot; + stringIndexMaxLength + &amp;quot;\\)&amp;quot;;
    while (matcher.find()) {
      int length = Integer.valueOf(matcher.group(1)).intValue();
      if (length &amp;gt; stringIndexMaxLength) {
        matcher.appendReplacement(sb, replacement);
        continue;
      } 
      matcher.appendReplacement(sb, &amp;quot;&amp;quot;);
    } 
    matcher.appendTail(sb);
    return sb.toString();
  } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;As per the implementation, if the query contains anything that
  matches &lt;strong&gt;[$COLUMN_LENGTH:&lt;/strong&gt; and the column length value
  is greater than the value mentioned in &lt;em&gt;
    &lt;strong&gt;database.string.index.max.length[DB_NAME]&lt;/strong&gt;&lt;/em&gt;
  property, it will replace the matched value in the query with &lt;strong&gt;(stringIndexMaxLength)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Is this correct implementation??? Because for Oracle database and &lt;em&gt;
    &lt;strong&gt;database.string.index.max.length[oracle]=1000&lt;/strong&gt;&lt;/em&gt;,
  it is generating a creating index query as below and ending up
  throwing an exception &lt;u&gt;
    &lt;em&gt;ORA-00904: &amp;quot;SAMLSPENTITYID&amp;quot;: invalid identifier_&lt;/em&gt;&lt;/u&gt;&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;From:
create index IX_87463CFB on SamlIdpSpConnection (companyId, samlSpEntityId[$COLUMN_LENGTH:1024$]);

To:
create index IX_87463CFB on SamlIdpSpConnection (companyId, samlSpEntityId(1000));&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;With Regards&lt;/p&gt;
&lt;p&gt;Rupal Chatterjee&lt;/p&gt;</summary>
    <dc:creator>Rupal Chatterjee</dc:creator>
    <dc:date>2021-09-22T10:15:09Z</dc:date>
  </entry>
</feed>
