-->
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: Is this many-to-one possible?
PostPosted: Fri Mar 27, 2009 1:42 pm 
Newbie

Joined: Wed Mar 04, 2009 3:26 pm
Posts: 4
Hey!

I have these two persistent classes:
Code:
public class Item{
    public virtual Int32 {get;set;}
    ...
}

public class ItemUpdate{
    public virtual Item Item {get; set;}
    public virtual DateTime Updated {get; set;}
    ...
}


The ItemUpdate table in the db has a foreign key to Item, so I can have many updates for a particular Item... I COULD map this relationship with a set or a bag or else... but this list isn't needed but for audits.

Only the last update is significant, so, rather than this:
Code:
public class Item{
    public virtual Int32 {get;set;}
    public virtual IList<ItemUpdate> ItemUpdates;
    ...
}


I need something like this:
Code:
public class Item{
    public virtual Int32 {get;set;}
    public virtual ItemUpdate LastUpdate {get;set;}
    ...
}


Is it possible to map this kind of stuff? Thanks in advance!

_________________
Darth Reisender


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 4:59 am 
Beginner
Beginner

Joined: Fri Sep 26, 2008 9:19 am
Posts: 20
Location: Belgium
[my post didn't come through correctly so now i created 2 replies: check following]


Last edited by santo2 on Tue Apr 07, 2009 5:04 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 5:03 am 
Beginner
Beginner

Joined: Fri Sep 26, 2008 9:19 am
Posts: 20
Location: Belgium
Hey,

You could fill it up yourself by getting a list with the criteria :
- ItemId = ..
- order by date desc
- set max result to 1

crit.AddOrder(Order.Desc("Date"));
crit.SetMaxResults(1);
crit.Add(Expression.Eq("ItemId",<id>);


item.LastUpdate = crit.List().First();


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.