-->
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.  [ 9 posts ] 
Author Message
 Post subject: mappedBy
PostPosted: Mon Mar 02, 2009 12:23 pm 
Newbie

Joined: Mon Mar 02, 2009 12:01 pm
Posts: 5
SORRY I POST THIS IN THE WROG FORUM BEFORE
Hi all.
I tried to search this through the forum but couldn't find it.

Is this valid
Code:
Class Father {
@OneToMany (mappedBy="grandFather.Father")
public Child getChild() {
return child;
}
}


Where Child class has the property Grandfather but not Father (this is just an example).

So basically I want to go 1 step deep.

Thanks in advance!

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 4:03 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
No, I don't think its possible.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 4:08 pm 
Newbie

Joined: Mon Mar 02, 2009 12:01 pm
Posts: 5
Hey there. Thanks for the quick reply.

Just for anyone who wants to know this. I figured it out.

All I had to do was
Code:
Class Father {
@OneToMany (mappedBy="grandFather")
public Child getChild() {
return child;
}
}


Where Father was mapped by Grandfather... Hibernate somehow knew internally that mapping. Pretty neat I would say :).

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 4:12 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
So your father is the grandfather of his kids? sounds weird...

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 4:19 pm 
Newbie

Joined: Mon Mar 02, 2009 12:01 pm
Posts: 5
Told you. It was just an example. Have to admit a bad one!

But I hope the concept is clear - on how to manage this deep hierarchy relationship.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 2:49 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Could you post a clearer example? just out of interest...

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 12:35 pm 
Newbie

Joined: Mon Mar 02, 2009 12:01 pm
Posts: 5
I will try. Please let me know if it is still unclear.

Bank offers Deals.
So on Java level, Bank has a List of Deal object.

Now Customer comes. He takes the deal and that creates a Contract.
A Customer can make many contracts.

So Customer->List<Contract>

Also, a Contract is something from a Deal.
So Contract has a foreign key from Deal.

Code:
class Bank{
mappedBy=Bank
private List<Deal> deals;
}

class Customer{
mappedBy=Customer
private List<Contract> contracts;
}

class Contract{
private Customer customer;
private Deal deal;
}

class Deal {
private Bank bank;
}


Hope it is clear till now.

Now on front end, I wanted to see how many contracts the Bank did (irrespective of customers).

So I just create a List of Contract in Bank, which is mappedBy=Deal

Code:
mappedBy=Deal
private List<Contract> contracts;


What did not work was
Code:
mappedBy=Deal.bank
private List<Contract> contracts;


May be I am just making it over complicated..... any suggestions are welcome.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 4:01 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Hmm, never seen that before. Are you sure it works correctly?

I'd probably have used a namedquery in order to count the contracts of a bank.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 4:04 am 
Newbie

Joined: Mon Mar 02, 2009 12:01 pm
Posts: 5
Hiya.
I don't have enough data in my DB right now to say a definite yes. But it seems to work.

I will post an update by EoW.

Cheers


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