-->
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: one to one relationship with List
PostPosted: Thu Jul 15, 2010 3:35 am 
Newbie

Joined: Thu Jul 15, 2010 3:26 am
Posts: 5
Hi,

I have two classes Sale and SalesUnit. Sale class have a list of SalesUnit. Sale and SaleUnit has a one to one relationship. Can anyone tel me how to Map this relationship? I couldn't find anything like this on the web..

Sale class

Code:
public class Sale
{
    private Long id;
    private Date soldDate;
    private List<SalesUnit> sales;

    public Sale(List sales)
    {
        soldDate=new Date();
        this.sales=sales;
    }
    public Sale()
    {
        soldDate=new Date();
    }
}



SalesUnit class

Code:
public class SalesUnit
{
    private Long salesID;
    private Item item;
    private Long quantity;
    private Double total;
    private Float discount;
    /** Creates a new instance of SalesUnit */
    public SalesUnit(Item item,Long quantity)
    {
        this.quantity=quantity;
        this.item=item;
       
    }
    public SalesUnit()
    {

    }
}


Top
 Profile  
 
 Post subject: Re: one to one relationship with List
PostPosted: Thu Jul 15, 2010 3:41 am 
Newbie

Joined: Tue Jul 13, 2010 1:30 am
Posts: 5
I feel it is one-to-many mapping////As per my knowledge//But why it is list?


Top
 Profile  
 
 Post subject: Re: one to one relationship with List
PostPosted: Thu Jul 15, 2010 3:49 am 
Newbie

Joined: Thu Jul 15, 2010 3:26 am
Posts: 5
Why do you say it is a one to many? Well My Sale object can have an unknown number of SalesUnit objects thats why it is in a list! Have i got the relationship wrong? Any suggestions?


Top
 Profile  
 
 Post subject: Re: one to one relationship with List
PostPosted: Thu Jul 15, 2010 4:42 am 
Newbie

Joined: Tue Jul 13, 2010 1:30 am
Posts: 5
unknown number of SalesUnit objects means i.e one to many right?


Top
 Profile  
 
 Post subject: Re: one to one relationship with List
PostPosted: Thu Jul 15, 2010 4:59 am 
Newbie

Joined: Thu Jul 15, 2010 3:26 am
Posts: 5
No it means a collection.... one to many is when oone entity is referencing another entity like A Book having an Author...


Top
 Profile  
 
 Post subject: Re: one to one relationship with List
PostPosted: Sat Jul 17, 2010 9:49 am 
Newbie

Joined: Thu Jul 15, 2010 3:26 am
Posts: 5
For anyone interested I did not find any solution for my specific question so i made do with a collection of components..


Top
 Profile  
 
 Post subject: Re: one to one relationship with List
PostPosted: Sun Jul 18, 2010 10:54 am 
Newbie

Joined: Sun Jul 18, 2010 10:15 am
Posts: 8
drajasuman was right, that is a one-to-many relationship as in, one Sale can have many SaleUnits

7.4.1 has your mapping:
http://docs.jboss.org/hibernate/stable/ ... tional-m21


Top
 Profile  
 
 Post subject: Re: one to one relationship with List
PostPosted: Sun Jul 18, 2010 11:14 am 
Newbie

Joined: Thu Jul 15, 2010 3:26 am
Posts: 5
Ok my mistake then.. Thank you for your help dude.. Cheers!


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.