-->
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.  [ 3 posts ] 
Author Message
 Post subject: foreign key into non-hibernate table
PostPosted: Thu May 25, 2006 8:16 am 
Newbie

Joined: Thu Jan 12, 2006 11:48 am
Posts: 2
Location: Elkridge, Maryland
Hibernate version: 3.1.1

Name and version of the database you are using: Oracle 9iR2

I have a legacy database with many tables not normally accessed by Hibernate. I would like to generate a new Hibernate object that has fields/columns that are foreign-keys into some of these legacy tables, but I don't want to have to create Hibernate objects for these legacy tables.

Is there a way to in my mapping file to tell hibernate that a given field is a foreign key on a legacy table for which no mapping file exists? I want to do this because I am using the Hibernate generated DDL to add the Hibernate-related tables to the database, and I would like to maintain my constraints (foreign key relationships).

The foreign-key options I've seen documented seem to only reference other Hibernate objects.

Thanks...

Jim Reitz


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 12:33 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
I don't see how that would be possible. Creating mappings and persistent objects is a snap with a Hibernate Tools plugin, since you just point it to the database and it's all generated for you automatically.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 27, 2006 3:43 am 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Hi!

If you cannot migrate the referenced tables in the same step (which may be impossible due to time-constraints or application structure), than the only way I see is, to reference only the foreign-key (as it is) in the Hibernate-mapped object. When you pass such Hibernate object into legacy sections, old-style SQL would access the foreign-key directly and use it.

However: In my experience it is much less work to create also a mapping for the referenced table than doing all such work-arounds. You may not want to convert all places in your application where you use the referenced object in the same time, but you can. And - because of the lazy loading - the referenced object is only fetched, when you actually call the getter. It also works for legacy code where you can get the ID from the mapped object. Try it! :-)

All the best,

René


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