-->
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.  [ 8 posts ] 
Author Message
 Post subject: Component confusion
PostPosted: Wed Aug 04, 2004 2:24 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
I'm a bit confused about components.

I have two classes, Customer and Property. Each class can have an Address, for example a customer lives at an address, and he might want to buy a new property, that has an address as well.

So Customer and Property both have a field on each class called address, of type Address.

Now looking at the documentation, it seems that I should create a component of address for both the Customer and Property mappings, and in each case detail all the fields of the Address class i.e. I'm duplicating the Address mapping on each class that references it.

On the face of it this seems pure madness, so I'm assuming I'm missing something big time. Should I be using component at all, and if I should, how do I share the mapping across multiple classes that use Address ?

_________________
On the information super B road


Top
 Profile  
 
 Post subject: Hi
PostPosted: Wed Aug 04, 2004 3:38 pm 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
I understand you want to translate an object oriented thinking to the mapping in Hibernate. This is, I think, not possible as the mapping document bridges the gap between object oriented and relational world.
You can be very 'fine'grained' in your Java-model, but the tables still have to be built the 'old' way.
Why is it madness, you think?
My experience is that changes to the DB-schema that took hours now can be made in seconds (with a little help from XDoclet and Hibernate tools....)
So rejoice over Hibernate!

Sincerely,


Top
 Profile  
 
 Post subject: a further explanation
PostPosted: Wed Aug 04, 2004 4:28 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
kantorn wrote:

Why is it madness, you think?
Sincerely,

The madness I was referring to to was that if you have say, 10 classes that all use address, my assumption is that you will have to duplicate the mapping code for address on each class that references address. I am more than likely wrong, but if I am right, than its madness (please someone hold up my hand and say I'm wrong).

Anyway, in essence all I'm trying to work out is a really simple mapping problem, how do I map this:

public class Customer {
private int id;
private Address address;
// getters and setters ommitted for brevity

}

public class Address {
private int id;
private String addressLine;
private String postCode;
}

to this database format

TABLE CUSTOMER with fields CUST_ID and foreign key ADDRESS_ID
TABLE ADDRESS with ADDRESS_ID ?

Help !

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 4:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Then make address a true entity instead of a component. Then you'd map it only once.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 4:43 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
XML entities

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 8:35 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
steve wrote:
Then make address a true entity instead of a component. Then you'd map it only once.


Can you give a poor newbie an extra hint here, an example would be great !

_________________
On the information super B road


Top
 Profile  
 
 Post subject: Docs!
PostPosted: Thu Aug 05, 2004 1:17 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Try the documentation:

Parent/child relation
http://www.hibernate.org/hib_docs/refer ... -manytoone

many-to-one
http://www.hibernate.org/hib_docs/refer ... -manytoone

Do as I did; print the docs, bind them in som kind of cosy plastic wrapper and sleep with them under your pillow. Hibernate is great, but does not explain itself. BTW, I still consult the docs regularly, and I'm not a newbie (at least not a fresh one) anymore.

Sincerely,

/C


Top
 Profile  
 
 Post subject: Ooops.
PostPosted: Thu Aug 05, 2004 1:18 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Parent/child example

http://www.hibernate.org/hib_docs/refer ... arentchild


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