-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using legacy schema, indices and one-one association
PostPosted: Tue Jan 04, 2005 12:14 pm 
Newbie

Joined: Tue Jan 04, 2005 11:06 am
Posts: 15
Hibernate version: 2.1.6

I am ramping up on a project that will be developed around
an existing DB2 database. I have successfully (using middlegen)
generated mapping files from DB2. These mapping files as
incomplete in that they do not contain any information about
associations. I understand this is to be expected and that
either hand-editing or the middlegen GUI can be used to correct this.

Since I am only working with two tables in a prototyping
mode, I hand-edited the two mapping files to define a
one-one mapping between the two classes. It just so
happens they are Client and Address and they work
exactly like the example in HinA (pp. 223-224 Using
A Primary Key Association).

So far, so good. From these mappings I generated Java
class (which looked like I would expect) and SQL. The SQL
was generated b/c I am going to do testing remotely (no
access to DB2) with a MySQL database.

I noticed in the SQL that (not really surprisingly) that the
following was generated:

The generated SQL (show_sql=true):

alter table ADDR add index FKEB2CBEC414381 (TAN), add constraint
FKEB2CBEC414381 foreign key (TAN) references CLIENT (TAN);

As I said, this is not too surprising, but it got me thinking:
If I hand-edit my mapping files to define the relationship
between Client and Address, how does Hibernate know
about that relationship in DB2?

It turns out in DB2 there is an index defined between CLIENT and
ADDR that links the two using TAN (accnt number). If I were to
retarget my prototype mapping files for DB2 would Hibernate
generate the exact SQL as the original DB admin did?

Perhaps, the answer is that for a given DB, there is only
one way to define a one-one relationship and Hibernate
knows how to make <one-to-one> element do the right
thing.

I hope I have made myself clear. If some Hibernate expert
tells me: "It just works" I will go with that.

Rob

_________________
Rob Gordon
SuffolkSoft, Inc.
Westby, WI


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 12:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It just works :)

If you have an existing DB and don't want any schema generation to take place, just don't use it (remove hibernate.hbm2ddl.auto from your config)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 2:39 pm 
Newbie

Joined: Tue Jan 04, 2005 11:06 am
Posts: 15
Quote:
Perhaps, the answer is that for a given DB, there is only
one way to define a one-one relationship and Hibernate
knows how to make <one-to-one> element do the right
thing.


Okay, I guess I am not that trusting. What I would really
like to hear "works" is the above assumption. That is,
given I have defined a one-to-one in a
mapping file that corresponds to a legacy schema, Hibernate
knows how to use the existing indices that define that
one-to-one. Is that the case?

The only reason I am generating sql is because for
prototype phase of project, I am recreating legacy
DB in MySQL.

Thanks
Rob

_________________
Rob Gordon
SuffolkSoft, Inc.
Westby, WI


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 10:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well I don't get exactly what your problem is, Hibernate does one-to-ones exactly the way you saw it ... what exactly is your question?


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