Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to upgrade database schema built with EclipseLink?
How to upgrade database schema built with EclipseLink? [message #390291] Thu, 16 July 2009 13:37 Go to next message
Eclipse UserFriend
Originally posted by: atrav99.web.de

Hi,

I'm looking for a general solution for upgrading database schema built
with EclipseLink. How do you do it in your projects?

The first solution that comes to my mind is to create my own mechanism
for upgrading databases, with SQL scripts doing all the work. But in
this case I'll have to remember about creating new scripts every time
the object mappings are updated. And I'll still have to deal with
low-level SQL queries, instead of just defining mappings and allowing
the ORM tools to do all the job...

So the question is how to do it properly. Maybe some tools allow for
simplifying this task (for example, I heard that Rails have such
mechanism built-in).

Thanks for any suggestions.

Markus
Re: How to upgrade database schema built with EclipseLink? [message #390501 is a reply to message #390291] Fri, 17 July 2009 06:20 Go to previous messageGo to next message
Enrico is currently offline EnricoFriend
Messages: 82
Registered: July 2009
Member
Hi MArkus,

I am not sure what do you mean with upgrade...d you mean update your
schema?If so, what about to use:

<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database"/>


in your persitence.xml file.

This will generate schema when you run your application, basing on
properties of your entities (if table). As options you can have:

* none – EclipseLink does not generate DDL; no schema is generated.
* create-tables – EclipseLink will attempt to execute a CREATE TABLE
SQL for each table. If the table already exists, EclipseLink will follow
the default behavior of your specific database and JDBC driver
combination (when a CREATE TABLE SQL is issued for an already existing
table). In most cases an exception is thrown and the table is not
created. EclipseLink will then continue with the next statement. (See
also eclipselink.create-ddl-jdbc-file-name.)
* drop-and-create-tables – EclipseLink will attempt to DROP all tables,
then CREATE all tables. If any issues are encountered, EclipseLink will
follow the default behavior of your specific database and JDBC driver
combination, then continue with the next statement. (See also
eclipselink.create-ddl-jdbc-file-name and
eclipselink.drop-ddl-jdbc-file-name.)

BR,
Enrico



Markus Zander ha scritto:
> Hi,
>
> I'm looking for a general solution for upgrading database schema built
> with EclipseLink. How do you do it in your projects?
>
> The first solution that comes to my mind is to create my own mechanism
> for upgrading databases, with SQL scripts doing all the work. But in
> this case I'll have to remember about creating new scripts every time
> the object mappings are updated. And I'll still have to deal with
> low-level SQL queries, instead of just defining mappings and allowing
> the ORM tools to do all the job...
>
> So the question is how to do it properly. Maybe some tools allow for
> simplifying this task (for example, I heard that Rails have such
> mechanism built-in).
>
> Thanks for any suggestions.
>
> Markus
Re: How to upgrade database schema built with EclipseLink? [message #390502 is a reply to message #390501] Fri, 17 July 2009 08:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: atrav99.web.de

Hi Enrico,

yes, I mean "update my schema". Your Idea is good for new tables. But
what, if I have to add a new field or key or if I have to split an
entity in two?

Here a very simple example:



Old version:
Entity "Student"
Attributes: Name, Registration No., Adress, Phone



New version:
Entity "Student"
Attributes: Sure Name, Given Name, Registration No., Street, City, Zip Code

Entity "Phone_Numbers"
Attribtutes: Registration No. (as foreign key), Phone type, Phone




How can I convert an existing database from "old version" to "new
version" without having database platform specific SQL statements?

Markus




Enrico schrieb:
> Hi MArkus,
>
> I am not sure what do you mean with upgrade...d you mean update your
> schema?If so, what about to use:
>
> <property name="eclipselink.ddl-generation" value="create-tables" />
> <property name="eclipselink.ddl-generation.output-mode" value="database"/>
>
>
> in your persitence.xml file.
>
> This will generate schema when you run your application, basing on
> properties of your entities (if table). As options you can have:
>
> * none – EclipseLink does not generate DDL; no schema is generated.
> * create-tables – EclipseLink will attempt to execute a CREATE TABLE SQL
> for each table. If the table already exists, EclipseLink will follow the
> default behavior of your specific database and JDBC driver combination
> (when a CREATE TABLE SQL is issued for an already existing table). In
> most cases an exception is thrown and the table is not created.
> EclipseLink will then continue with the next statement. (See also
> eclipselink.create-ddl-jdbc-file-name.)
> * drop-and-create-tables – EclipseLink will attempt to DROP all tables,
> then CREATE all tables. If any issues are encountered, EclipseLink will
> follow the default behavior of your specific database and JDBC driver
> combination, then continue with the next statement. (See also
> eclipselink.create-ddl-jdbc-file-name and
> eclipselink.drop-ddl-jdbc-file-name.)
>
> BR,
> Enrico
>
>
>
> Markus Zander ha scritto:
>> Hi,
>>
>> I'm looking for a general solution for upgrading database schema built
>> with EclipseLink. How do you do it in your projects?
>>
>> The first solution that comes to my mind is to create my own mechanism
>> for upgrading databases, with SQL scripts doing all the work. But in
>> this case I'll have to remember about creating new scripts every time
>> the object mappings are updated. And I'll still have to deal with
>> low-level SQL queries, instead of just defining mappings and allowing
>> the ORM tools to do all the job...
>>
>> So the question is how to do it properly. Maybe some tools allow for
>> simplifying this task (for example, I heard that Rails have such
>> mechanism built-in).
>>
>> Thanks for any suggestions.
>>
>> Markus
Re: How to upgrade database schema built with EclipseLink? [message #390503 is a reply to message #390502] Fri, 17 July 2009 08:45 Go to previous messageGo to next message
Enrico is currently offline EnricoFriend
Messages: 82
Registered: July 2009
Member
Yes, you are right.
I don't know if there is a solution for that without write specific sql
scritps.
I am too interested to know if there is something better.
Hope to have some reply from the community.

BR,
Enrico

Markus Zander ha scritto:
> Hi Enrico,
>
> yes, I mean "update my schema". Your Idea is good for new tables. But
> what, if I have to add a new field or key or if I have to split an
> entity in two?
>
> Here a very simple example:
>
>
>
> Old version:
> Entity "Student"
> Attributes: Name, Registration No., Adress, Phone
>
>
>
> New version:
> Entity "Student"
> Attributes: Sure Name, Given Name, Registration No., Street, City, Zip Code
>
> Entity "Phone_Numbers"
> Attribtutes: Registration No. (as foreign key), Phone type, Phone
>
>
>
>
> How can I convert an existing database from "old version" to "new
> version" without having database platform specific SQL statements?
>
> Markus
>
>
>
>
> Enrico schrieb:
>> Hi MArkus,
>>
>> I am not sure what do you mean with upgrade...d you mean update your
>> schema?If so, what about to use:
>>
>> <property name="eclipselink.ddl-generation" value="create-tables" />
>> <property name="eclipselink.ddl-generation.output-mode"
>> value="database"/>
>>
>>
>> in your persitence.xml file.
>>
>> This will generate schema when you run your application, basing on
>> properties of your entities (if table). As options you can have:
>>
>> * none – EclipseLink does not generate DDL; no schema is generated.
>> * create-tables – EclipseLink will attempt to execute a CREATE TABLE
>> SQL for each table. If the table already exists, EclipseLink will
>> follow the default behavior of your specific database and JDBC driver
>> combination (when a CREATE TABLE SQL is issued for an already existing
>> table). In most cases an exception is thrown and the table is not
>> created. EclipseLink will then continue with the next statement. (See
>> also eclipselink.create-ddl-jdbc-file-name.)
>> * drop-and-create-tables – EclipseLink will attempt to DROP all
>> tables, then CREATE all tables. If any issues are encountered,
>> EclipseLink will follow the default behavior of your specific database
>> and JDBC driver combination, then continue with the next statement.
>> (See also eclipselink.create-ddl-jdbc-file-name and
>> eclipselink.drop-ddl-jdbc-file-name.)
>>
>> BR,
>> Enrico
>>
>>
>>
>> Markus Zander ha scritto:
>>> Hi,
>>>
>>> I'm looking for a general solution for upgrading database schema
>>> built with EclipseLink. How do you do it in your projects?
>>>
>>> The first solution that comes to my mind is to create my own
>>> mechanism for upgrading databases, with SQL scripts doing all the
>>> work. But in this case I'll have to remember about creating new
>>> scripts every time the object mappings are updated. And I'll still
>>> have to deal with low-level SQL queries, instead of just defining
>>> mappings and allowing the ORM tools to do all the job...
>>>
>>> So the question is how to do it properly. Maybe some tools allow for
>>> simplifying this task (for example, I heard that Rails have such
>>> mechanism built-in).
>>>
>>> Thanks for any suggestions.
>>>
>>> Markus
Re: How to upgrade database schema built with EclipseLink? [message #631668 is a reply to message #390291] Fri, 08 October 2010 12:25 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 1
Registered: October 2010
Junior Member
Hi,

I have faced with same problem as yours.Did you find any way to update schema when you make some changes on entity?

Thanks in advance.

Eclipse User wrote on Thu, 16 July 2009 09:37
Originally posted by: atrav99.web.de

Hi,

I'm looking for a general solution for upgrading database schema built
with EclipseLink. How do you do it in your projects?

The first solution that comes to my mind is to create my own mechanism
for upgrading databases, with SQL scripts doing all the work. But in
this case I'll have to remember about creating new scripts every time
the object mappings are updated. And I'll still have to deal with
low-level SQL queries, instead of just defining mappings and allowing
the ORM tools to do all the job...

So the question is how to do it properly. Maybe some tools allow for
simplifying this task (for example, I heard that Rails have such
mechanism built-in).

Thanks for any suggestions.

Markus

Re: How to upgrade database schema built with EclipseLink? [message #632409 is a reply to message #631668] Tue, 12 October 2010 19:28 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

There is no such feature in EclipseLink. If you want to ALTER an existing database schema, you need to do this yourself. EclipseLink can drop and recreate the schema, but not alter it.

If you want alter support please log a bug and vote for it.


James : Wiki : Book : Blog : Twitter
Re: How to upgrade database schema built with EclipseLink? [message #754894 is a reply to message #632409] Fri, 04 November 2011 19:52 Go to previous message
Fabio Russo is currently offline Fabio RussoFriend
Messages: 2
Registered: November 2011
Junior Member
Hi people,
What I do in this case is use hibernate-tools to do schema-update.
It's quick and easy and you can use it as a maven plug-in.
So any time you build your application you will have yoour schema updated.
You can also use it as an ant tool. But you'll have to configure ant, what can be not as easy as it seems.

cheers
Re: How to upgrade database schema built with EclipseLink? [message #754896 is a reply to message #632409] Fri, 04 November 2011 19:52 Go to previous message
Fabio Russo is currently offline Fabio RussoFriend
Messages: 2
Registered: November 2011
Junior Member
Hi people,
What I do in this case is use hibernate-tools to do schema-update.
It's quick and easy and you can use it as a maven plug-in.
So any time you build your application you will have yoour schema updated.
You can also use it as an ant tool. But you'll have to configure ant, what can be not as easy as it seems.

cheers
Previous Topic:Custom sequence
Next Topic:Partition - id on new entities?
Goto Forum:
  


Current Time: Sat Apr 20 03:57:49 GMT 2024

Powered by FUDForum. Page generated in 0.03874 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top