-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Telling Hibernate to only generate ddl for the changes...
PostPosted: Mon Nov 27, 2006 5:45 am 
Newbie

Joined: Wed Aug 18, 2004 10:44 am
Posts: 14
Hi,

This is a more general question, but since I'm using JPA I think this is the right forum to post it to.

We are using hbm2ddl to generate a ddl-file, and import it into the server-application.

In the next version, we have made a few changes, and don't want Hibernate to generate a full ddl, but just a dll of changes, only e.g. alter statements for the existing tables.

Is there a way to do that? In order to do a thing like this, Hibernate must no what has been changed and what has not, e.g. using some kind of annotation @since_version1.2 ore something. Or?

Regards,
René


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 12:41 pm 
Newbie

Joined: Mon Jan 05, 2004 11:04 am
Posts: 16
Hi,

try this (Hibernate Reference page 196)

20.1.6. Using Ant for incremental schema updates

You can call SchemaUpdate from the Ant script:
<target name="schemaupdate">
<taskdef name="schemaupdate"
classname="org.hibernate.tool.hbm2ddl.SchemaUpdateTask"
classpathref="class.path"/>
<schemaupdate
properties="hibernate.properties"
quiet="no">
<fileset dir="src">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaupdate>
</target>

Take care to use it not in production ;--)

_________________
_________________
Siegbert

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 3:21 am 
Newbie

Joined: Wed Aug 18, 2004 10:44 am
Posts: 14
Hmmmm, let me see.

So if I understand schemaupdate right, it does something like this:

1. It checks/compares the database tables and relations with the entities.

2. If there are changes they are updated in the database.

If this is true, it is not good enough for me, or is it? I want something like this:

If I release version 1.0 of my application, I create a version1.0.ddl and inject it into the production database.

After some changes in the entities i release a version 1.1 of my application, and create a version1.1.ddl of my database. I cannot inject this directly into the production database, cause it will remove the existing data.

I want something like a diff-1.1_to_1.0.ddl containing just the difference and inject that into the production database.

Maybe I could do something like this, in order to create the diff-1.1_to_1.0.ddl

In the develop environment, running 1.1, I inject the version1.0.ddl into the development database. Now I call schemaupdate, and ask it to generate a ddl (guess this is possible). This would give me diff-1.1_to_1.0.ddl, right?

-

Just to make things clear, I know this approach is not always a good idea. If you change the type of af field (from string to int) you loose data I guess and would schemaupdate know how to deal with this? But ok, if you know what you are doing, and plan right, you should be able to avoid these kind of problems.

Regards,
René


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 8:19 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

if you have the hbm2ddl.auto set to "update" it might be able to provide the functionality you need.

When you add a new persistent variable to an entity and then re-deploy, an extra column will be added to the respective table. When removing a variable and then re-deploying the column will be left in the table, so no data will be lost (allowing you to revert to an older version if required). Changing datatype of a variable will not (in my case anyway) do anything in the db, this will cause problems in your application.

You also need to consider the datatypes of the variables you are adding (best to wrapper variables in my opinion), for example use java.lang.Integer instead of int because java.lang.Integer can be null and int cannot.


Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 9:45 am 
Newbie

Joined: Sun Aug 14, 2005 3:08 am
Posts: 5
Hi!

Any solution to the problem yet? I also want to use JPA with Hibernate and I'm looking for a way version schema changes together with the releases/builds.

The reason is simple. I want to use Hibernate in a distributed environment with a lot small, cheap databases. Upgrading them by hand would be painful. Instead I'm looking for a way to generate upgrade scripts during build which could be tuned by a DBA before deployment.

Any pointers appreciated.

Thanks,
KM


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.