-->
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.  [ 6 posts ] 
Author Message
 Post subject: java src --> hib mapping generated --> DB Schema gener
PostPosted: Thu Jul 22, 2004 11:18 am 
Newbie

Joined: Wed Jul 14, 2004 8:09 pm
Posts: 6
Location: Sofia, Bulgaria
Intro:
I want to make an application which is quite flexible and
has a completely Object-driven model ( say my model is an
UML diagram from which I can generate and regenerate the sources
for my persistent classes which are just some
POJO / JavaBean classes ).

Then as a first step I generate my XML mapping from these java
sources and as a second step I export the mapping to a DB Schema.

The problem/question:
Now when I change the hibernate XML mapping either as a result of
changing my model or directly ( for example I open my hibernate
XML mapping and I add a new unique
constraint on some property of some persistent class )
I want my DB Schema automatically get in synch with
these changes in the mapping.

How does one do this ? I exclude as a decision of my problem
running a .bat everytime I change my mapping. I want to just be
able at runtime do these changes in my schema. Is that
possible ( I guess it is ) and if so what is the right way
( the best way ) of achieving it ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 6:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The tools have Ant tasks so you can chain them through dependencies or calling the appropriate targets directly.


Top
 Profile  
 
 Post subject: transparent synch ...
PostPosted: Fri Jul 23, 2004 4:02 am 
Newbie

Joined: Wed Jul 14, 2004 8:09 pm
Posts: 6
Location: Sofia, Bulgaria
Well, my question was am I able to keep my DB Schema in synch
by not calling external tools ( .bat files , ant tasks ).

I just at every startup of my application to make it so that the
application read the mapping XML ( all my mappings are
defined in a sigle XML file ). And if there has been a change
in the mapping since the latest startup let's say call some
method which updates the DB schema.

This way my application keeps the DB schema in synch
transparently and I don't need to worry about when my
mapping has been changed. I always have the guarentee that
if I restart the application everything is in synch
( XML mapping -> DB schema ).

That's what I want.

Could you ( or someone else ) be more precise and give me
some more details. Thank you very much in advance.

_________________
Peter Petrov


Top
 Profile  
 
 Post subject: About net.sf.hibernate.tool.hbm2ddl.SchemaUpdate
PostPosted: Fri Jul 23, 2004 4:49 am 
Newbie

Joined: Wed Jul 14, 2004 8:09 pm
Posts: 6
Location: Sofia, Bulgaria
Well, I had a more detailed look at the following class:
net.sf.hibernate.tool.hbm2ddl.SchemaUpdate

From the its code it's visible that it doesn't update
the DB schema if too fine-grained changes are made in the
mapping XML file.

For example the tool will make an update to
some table if a new column has been added ( new column
defined in the mapping XML file ) to that table, but it
won't make any updates if you just made an already
existing column "unique". So it won't detect such a change and
generate a script to add a unique index/constraint to the DB.

_________________
Peter Petrov


Top
 Profile  
 
 Post subject: net.sf.hibernate.cfg.Configuration.generateSchemaUpdateScrip
PostPosted: Fri Jul 23, 2004 4:55 am 
Newbie

Joined: Wed Jul 14, 2004 8:09 pm
Posts: 6
Location: Sofia, Bulgaria
Actually the "update logic" I am talking about in my previous
reply is implemented in the method
net.sf.hibernate.cfg.Configuration.generateSchemaUpdateScript.

And all the SchemaUpdate tool does is just call that method
to get a script which is then sent for execution to the DB.

Well, apparently you won't be able to update too much if
you use that kind of "update logic".

Maybe I have to think about extending the Configuration class
or simply implementing my own update logic in my
own tool similar to SchemaUpdate but providing me
with more logic about more fine-grained update-cases.

Right ?

_________________
Peter Petrov


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 9:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Modify update schema and submit the patch so others can benefit as well is the way to go :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.