Unable to create entity  because column name exceeds 30 characters

John O'Flaherty, modified 7 Years ago. New Member Posts: 14 Join Date: 1/25/14 Recent Posts

Hi all,

I am in the process of migrating 6.2 portlet code over to DXP, many issues mostly resolved however this one eludes me as yet. In my service.xml we can have table and column names longer than 30 characters. In 6.2 this didn't seem to cause any issues however in DXP i get the below message: 

Unable to create entity  because column name exceeds 30 characters. Some databases do not allow column names longer than 30 characters. To disable this warning set the "service-builder" attribute "database-name-max-length" to the max length that your database supports. 

 

This is a clear message about whats happened, however what isn't clear is to where to set this attribute and value. It would be helpful to be able to set for both table names and column names.

I'd appreciate any assistance ,

Regards,

John

thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

In your service.xml file, <service-builder /> is the root element.  Add the "database-name-max-length" attribute on the root element.

 

Me, I never really do this.  I tend to use nice clean entity names per java standards, but I'll also add the db-name and table-name attributes on the <entity /> and <column /> tags to use more compressed names following db naming standards.

 

Note that the 30 char max was for those DBs where this kind of thing can be a PITA to identify and resolve, so putting the message in early was seen  as a way to prevent getting all the way down the road only to encounter it during deployment.

thumbnail
Jorge Díaz, modified 7 Years ago. Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts

Oracle database 12.1 and older versions don't support table names longer than 30 characters, see: https://stackoverflow.com/questions/756558/what-is-the-maximum-length-of-a-table-name-in-oracle#756569

thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

30 chars sounds like enough, but when you specify the namespace and use Java-standard naming, SB will create the table as NAMESPACE_ENTITYNAME and that often will exceed the 30.

 

Kevin Neibarger, modified 6 Years ago. Regular Member Posts: 105 Join Date: 2/2/18 Recent Posts
David H Nebinger<p>30 chars sounds like enough, but when you specify the namespace and
use Java-standard naming, SB will create the table as
NAMESPACE_ENTITYNAME and that often will exceed the 30.</p>
<p> </p>


Is there anyway for the service builder to ignore appending the namespace? In my 6.2 legacy code entities were created without actual tables to serve as placeholders. It was done this way to wrap FinderImpl which called SQL queries. Since the module-hbm.xml appends the namespace for tables we get all kinds of compile errors on the generated classes. Worst case scenario I can pull out these "empty" entities and manually build the api behind them, but it would work better if we could just ignore the namespace appended to the entity name.
William Berks, modified 7 Years ago. New Member Post: 1 Join Date: 1/27/14 Recent Posts

The DTD, http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd, does not define a 'database-name-max-length' attribute for the service-builder element.  If I try to add it anyway, I still get the name length error when trying to run the service builder.

 

I would love to change the column name, but this is an existing database.

Surendra K, modified 7 Years ago. New Member Posts: 17 Join Date: 9/10/14 Recent Posts

Hi William

 

Add databaseNameMaxLength=100 attribute in build.gradle file of your service module.

 

ex

 

buildService {
    apiDir = "../microservices-api/src/main/java"
    databaseNameMaxLength=100
}

Manushi Jani, modified 5 Years ago. New Member Posts: 9 Join Date: 2/13/15 Recent Posts
<p>This works perfect for liferay 7.0,7.1,7.2.</p>

<p>Thanks a lot!!</p>
John O'Flaherty, modified 7 Years ago. New Member Posts: 14 Join Date: 1/25/14 Recent Posts

Hi William,

 

I was able to set the following and service builder didn't throw any issues for me. 

 

<service-builder database-name-max-length="999" package-path="com.qad.meetingroomdisplays">
    <author>j2o</author>
    <namespace>MeetingRoomDisplays</namespace>
    <database-name-max-length>999</database-name-max-length>
 

I hope that helps,

 

John

 

thumbnail
Pasi Kössi, modified 6 Years ago. New Member Posts: 12 Join Date: 10/13/08 Recent Posts
William Berks:

The DTD, http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd, does not define a 'database-name-max-length' attribute for the service-builder element.  If I try to add it anyway, I still get the name length error when trying to run the service builder.

 

I would love to change the column name, but this is an existing database.

This seems to be fixed in  http://www.liferay.com/dtd/liferay-service-builder_7_1_0.dtd. The attribute is now allowed.
John O'Flaherty, modified 6 Years ago. New Member Posts: 14 Join Date: 1/25/14 Recent Posts
Thanks Pasi Kössi, another reason to move to 7.1 :)
Manushi Jani, modified 5 Years ago. New Member Posts: 9 Join Date: 2/13/15 Recent Posts

<blockquote>
<div class="quote-title">William Berks:</div>
<div class="quote">
<div class="quote-content">
<p>The DTD, <a
href="http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd">http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd</a>,
does not define a 'database-name-max-length' attribute for the
service-builder element.  If I try to add it anyway, I still get
the name length error when trying to run the service builder.</p>
<p> </p>
<p>I would love to change the column name, but this is an existing database.</p></div></div></blockquote>
This seems to be fixed in
 http://www.liferay.com/dtd/liferay-service-builder_7_1_0.dtd. The
attribute is now allowed.

This is not allowed in Liferay 7.2
Pankaj Kumar, modified 5 Years ago. Regular Member Posts: 101 Join Date: 7/27/14 Recent Posts
It's worked for me in DXP 7.2
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
See https://issues.liferay.com/browse/LRDOCS-5449 for an alternative solution