Foren

changes in model-hint have no effect on tables

thumbnail
Alain Dresse, geändert vor 12 Jahren.

changes in model-hint have no effect on tables

Junior Member Beiträge: 95 Beitrittsdatum: 18.07.11 Neueste Beiträge
Hi,

We have an issue with columns in mysql tables suddenly changing, not abiding by the information in portlet-model-hints.xml. Previous versions of the portlet worked fine. Changes occured after making another modification to the service, and rebuilding the service.

we are using liferay 6.1 GA1. community edition. We have the issue when deploying the portlet on an plain liferay installation.

Our service.xml contains:
<service-builder package-path="org.bamboost.portlet.velocity">
	<author>parvn</author>
	<namespace>VT</namespace>

	<entity name="VelocityTemplate" local-service="true" remote-service="false" json-enabled="false">

		<!-- PK fields -->

		<column name="Id" type="long" primary="true" />

		<!-- Audit fields -->

		<column name="name" type="String" localized="false" id-type="class" />
		<column name="description" type="String" localized="false" />
		<column name="initTemplate" type="String" />
		<column name="mainTemplate" type="String" />

		<!-- Other fields -->

		<!-- Order -->
        <column name="key" type="String"></column>

		<order by="asc">
			<order-column name="name" />
		</order>

		<!-- Finder methods -->
        <finder name="Key" return-type="VelocityTemplate">
            <finder-column name="key"></finder-column>
        </finder>
	</entity>
</service-builder>


portlet-model-hints.xml indicates that the fields mainTemplate and initTemplate should be CLOBs:
		<field name="initTemplate" type="String">
			<hint-collection name="CLOB" />
		</field>
		<field name="mainTemplate" type="String">
			<hint-collection name="CLOB" />
		</field>


The SQL in tables.sql gets correctly updated as

	create table VT_VelocityTemplate (
		Id LONG not null primary key,
		name VARCHAR(75) null,
		description STRING null,
		initTemplate TEXT null,
		mainTemplate TEXT null,
		key_ VARCHAR(75) null
	);

but when the tables are created in mysql, initTemplate and mainTemplate are of type VARCHAR(255).

The tomcat log mentions
23:03:58,111 WARN  [BaseDB:382] Table 'VT_VelocityTemplate' already exists: create table VT_VelocityTemplate (Id bigint not null primary key,name varchar(75) null,description longtext null,initTemplate longtext null,mainTemplate longtext null,key_ varchar(75) null) engine InnoDB;


And the mysql log, show an incorrect

 create table VT_VelocityTemplate (Id bigint not null, name varchar(255), description varchar(255), initTemplate varchar(255), mainTemplate varchar(255), key_ varchar(255), primary key (Id))


a few lines before the correct

 create table VT_VelocityTemplate (Id bigint not null primary key,name varchar(75) null,description varchar(255) null,initTemplate longtext null,mainTemplate longtext null,key_ varchar(75) null) engine InnoDB


Any idea how to avoid the first, erroneous create of the sql table ?

Thanks and best regards,
Alain
thumbnail
David H Nebinger, geändert vor 12 Jahren.

RE: changes in model-hint have no effect on tables

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
Alain Dresse:
Changes occured after making another modification to the service, and rebuilding the service.


This has never worked. When deployed the first time only, the table will be created according to the script.

Any subsequent changes to the service (and therefore the script), are not automatically applied after deployment.

You (the developer) are always responsible for managing DDL changes to tables on your own.
thumbnail
Hitoshi Ozawa, geändert vor 12 Jahren.

RE: changes in model-hint have no effect on tables

Liferay Legend Beiträge: 7942 Beitrittsdatum: 24.03.10 Neueste Beiträge
initTemplate was probably VARCHAR(255).
You'll have to drop the table from the database and let Liferay recreate it. Liferay doesn't alter table if it already exists. If you already have data in it, you can do the alter table manually or change the name of the table and redeploy the portlet and let Liferay recreate the table and migrate your data.
thumbnail
Alain Dresse, geändert vor 12 Jahren.

RE: changes in model-hint have no effect on tables

Junior Member Beiträge: 95 Beitrittsdatum: 18.07.11 Neueste Beiträge
Thanks for the quick replies !

We are installing the portlets on a plain vanilla liferay, so my tables don't yet exist. The database 'only' contains the tables from the liferay installation.

Mysql actually gets two "create table" instructions for the tables corresponding to my portlet when we install it, the first one with the initTemplate as varchar(255).

I admin to lazyness emoticon - we had hoped in earlier times that hibernate could manage the alter tables, at least in the developer environment, and had added
hibernate.hbm2ddl.auto=update

to our portal-ext.properties.

With our changed approach (fresh installation on plain vanilla liferay from a script), this is no longer needed, and we will manage explicitly any code needed to maintain the information in the production environment during upgrades.

When I remove the hibernate.hbm2ddl.auto=update, then my tables are created correctly, which is a great relief. They are still two attempts to create the tables though, as reflected in the catalina.log as

07:48:00,222 INFO  [ServiceComponentLocalServiceImpl:183] Running VT SQL scripts
07:48:00,234 WARN  [BaseDB:382] Table 'VT_VelocityTemplate' already exists: create table VT_VelocityTemplate (Id bigint not null primary key,name varchar(75) null,descr
iption varchar(255) null,initTemplate longtext null,mainTemplate longtext null,key_ varchar(75) null) engine InnoDB;


Any idea why this happens ? As long as the 'create' instructions are identical, it doesn't really harm, but I know by experience (origin of this thread) that they can be different.
And when they are, it hurts...

Best,
Alain