Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Phoenix Zerin
Liferay IDE refuses to recreate dropped database table
September 6, 2011 10:22 AM
Answer

Phoenix Zerin

Rank: Junior Member

Posts: 60

Join Date: June 28, 2011

Recent Posts

I'm trying to figure out how to get Liferay to create a string column in a database table that is longer than 75 characters. I started trying to follow the instructions in this thread and this one, but I'm running into a particularly frustrating problem that is preventing me from continuing.

After my first attempt to add model hints failed (the column was created as a `varchar(75)`), I dropped the table (so that I could verify if subsequent attempts to add model hints fail that it was in fact getting rebuilt incorrectly vs. Liferay recognizing that the table already exists and not updating it).

Now I can't get Liferay to rebuild the missing table. At all.

I've tried stopping and restarting the server, I've rebuilt the service both with the server running and with the server stopped, I've updated the build number in service.properties, I've tried redeploying the containing plugin portlet in Liferay IDE. Nothing seems to be working.

How do I get Liferay to recreate a dropped database table for a service defined in a plugin portlet?
Phoenix Zerin
RE: Liferay IDE refuses to recreate dropped database table
September 7, 2011 12:10 PM
Answer

Phoenix Zerin

Rank: Junior Member

Posts: 60

Join Date: June 28, 2011

Recent Posts

One thing I did not try is manually undeploying and *then* redeploying the plugin portlet.

I removed the portlet from the server (by highlighting the portlet in the Servers pane in Liferay IDE and deleting it), and then I redeployed it (dragged the project directory from the Package Explorer onto the server in the Servers pane), and the database table was recreated.
Phoenix Zerin
RE: Liferay IDE refuses to recreate dropped database table
September 7, 2011 12:10 PM
Answer

Phoenix Zerin

Rank: Junior Member

Posts: 60

Join Date: June 28, 2011

Recent Posts

Nevermind; it seems that even though undeploying and redeploying the portlet worked the first time, it doesn't work for subsequent attempts.

What is the sequence that I need to follow to get Liferay to rebuild my database table?
Hajri Mohamed
RE: Liferay IDE refuses to recreate dropped database table
September 8, 2011 7:33 AM
Answer

Hajri Mohamed

Rank: Junior Member

Posts: 71

Join Date: March 2, 2011

Recent Posts

go to WEBINF, sql, tables.sql and copy the generated script for the choosen table, and execute it manually in your database server
regards
Phoenix Zerin
RE: Liferay IDE refuses to recreate dropped database table
September 8, 2011 9:01 AM
Answer

Phoenix Zerin

Rank: Junior Member

Posts: 60

Join Date: June 28, 2011

Recent Posts

Thanks Hajri. That works, but I have to modify the generated SQL (the generated SQL specifies "LONG" as the type for the ID column, which MySQL doesn't like so much), plus I also have to execute the code in indexes.sql.

This is a pretty arduous process to go through, especially when Liferay can do it automatically (since it does this the first time a portlet is deployed). Is there not a file I can edit to get Liferay to rebuild the database table when it deploys the portlet?

How does Liferay normally handle updates to database schemas?
Hajri Mohamed
RE: Liferay IDE refuses to recreate dropped database table
September 8, 2011 6:52 PM
Answer

Hajri Mohamed

Rank: Junior Member

Posts: 71

Join Date: March 2, 2011

Recent Posts

yes, if i remember you should change Long to bigint for MySQL, sorry for not telling you about this.
for the Liferay autoupgrade database tables when the deploy process take place, Liferay, by default will try to execute your tables.sql script every time you hotDeploy your plugin portlet, because, the first time you built your service.xml file, another file called service.properties file will be generated (you can find it under WEBINF, src),
this is my service.porperties file :

 1##
 2## Properties Override
 3##
 4
 5    #
 6    # Specify where to get the overridden properties. Updates should not be made
 7    # on this file but on the overridden version of this file.
 8    #
 9    include-and-override=service-ext.properties
10
11##
12## Build
13##
14
15    build.namespace=Custum
16    build.number=12
17    build.date=1315496961593
18    build.auto.upgrade=true
19
20##
21## Spring
22##
23
24    #
25    # Input a list of comma delimited Spring configurations. These will be
26    # loaded after the bean definitions specified in the
27    # portalContextConfigLocation parameter in web.xml.
28    #
29    spring.configs=\
30        WEB-INF/classes/META-INF/base-spring.xml,\
31        \
32        WEB-INF/classes/META-INF/hibernate-spring.xml,\
33        WEB-INF/classes/META-INF/infrastructure-spring.xml,\
34        \
35        WEB-INF/classes/META-INF/cluster-spring.xml,\
36        \
37        WEB-INF/classes/META-INF/portlet-spring.xml,\
38        \
39        WEB-INF/classes/META-INF/dynamic-data-source-spring.xml,\
40        WEB-INF/classes/META-INF/shard-data-source-spring.xml,\
41        \
42        WEB-INF/classes/META-INF/ext-spring.xml


the attribute that is important for us is the build.auto.upgrade=true (this is by default), if you want to diseable it, you have to create a file called service-ext.properties and copy paste service.properties into it, sure you will have to change build.auto.upgrade=false.
another thing, when trying to autoupgrade your database, Liferay will find that your tables already exists, so it will throw some exeptions related to (cannot delete or update a child row .........)
For me, how i work with service builder : i try to do the minimum with service.xml (just the tables structures and their primary key, sometimes i need some Finders too) and then i add foreign keys and all other constraints directly using the database , why i do this ? because service builder is not yet complete, exemple, you cannot define a foreign key !!!! anyway, this is how i do, hope this will help you

regards