Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Unable to create entity because column name exceeds 30 characters
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
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.
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
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.
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.
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.
Hi William
Add databaseNameMaxLength=100 attribute in build.gradle file of your service module.
ex
buildService {
apiDir =
"../microservices-api/src/main/java"
databaseNameMaxLength=100
}
<p>Thanks a lot!!</p>
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
This seems to be fixed in http://www.liferay.com/dtd/liferay-service-builder_7_1_0.dtd. The attribute is now allowed.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.
<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
Powered by Liferay™