-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping first entry of many-to-one to a single property
PostPosted: Tue Sep 13, 2005 11:53 am 
Newbie

Joined: Fri Oct 31, 2003 3:14 pm
Posts: 12
Location: New York, NY
Hibernate version: 3.0.5

Assume the following tables:

Code:
Foo (
id int not null primary key,
name varchar not null
)

Bar (
id int not null primary key,
foo_id int not null,
status_date date not null,
modified_date date not null
)


And the following classes:

Code:
class Foo {
int id;
String name;
Set<Bar> bars;
Bar bar;
}

class Bar {
int id;
Foo foo;
Date statusDate;
Date modifiedDate;
}


I want to map a particular Bar object to the Bar property of Foo based on an "order by" of the status and modified date columns. I understand that I can order the Set of Bar objects using order-by in the mapping. But I can't think of how to map the property.

And I need it mapped as a property for later queries for Foo that are based on properties of the most recent Bar and also for ordering the results of queries for Foo by the properties of the most recent Bar.

(Please note, these classes are simplified versions of the actual classes, both have many more properties)

I was thinking maybe I could use a <property> with a nested <formula> for the Bar, but I don't think I can return presisent entity references in formulas as I seem to have read they are pure SQL only.

Any ideas?

Thanks in advance,
Patrick


Top
 Profile  
 
 Post subject: Re: Mapping first entry of many-to-one to a single property
PostPosted: Tue Mar 07, 2006 4:58 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
I've run into this issue now as well. Can anyone offer help in mapping a single object from a collection, possibly with a <formula>, as a <many-to-one> of to the parent object.

for example

Customer
-------------
id
name
primaryContact (many-to-one)

CustomerContact
--------------------
id
customerId
primaryInd
contactInfo

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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