-->
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: How to map a very simple order / lines reference
PostPosted: Wed Jul 17, 2013 1:19 pm 
Newbie

Joined: Wed Jul 17, 2013 1:09 pm
Posts: 1
Hi All,
I have the simplest application wise situation :
- a Order class (which has a number of lines to be accessed)
- a Line class (which has one single Order)
I know it is a OneToMany/ManyToOne relation BUT... the owner is the Order not the line !
I know I'm looking like stupid but I'm not able to define such a situation.
Just to complete I'm speaking of persistence using JPA and EJB 3.X as environment.
Any help for this stupid guy (me) would be really appreciated
Thank you very much just for reading, answering would be nice
Best Regards
Franco


Top
 Profile  
 
 Post subject: Re: How to map a very simple order / lines reference
PostPosted: Mon Jul 22, 2013 5:32 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
For a one to many relationship for all the lines of the order, you can have this in line class :
@OneToMany
@JoinColumn(name = "line_id")
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Set<Line> getLines() {
return lines;
}

public void setLines(final Set<Line> lines) {
this.lines = lines;
}


And in the line class for a many to one relation to single order :
@ManyToOne(targetEntity = Order.class)
@JoinColumn(name = "order_id", referencedColumnName = "order_id", unique = false, insertable = true, updatable = true, nullable=false)
public Order getOrder() {
return order;
}

public void setPricingGroup(FlsUnitWeekPricingGroup pricingGroup) {
this.pricingGroup = pricingGroup;
}

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


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.