It's not a secret anymore!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes @ManyToOne RelationShip Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "@ManyToOne RelationShip" Watch "@ManyToOne RelationShip" New topic
Author

@ManyToOne RelationShip

panki vijay
Greenhorn

Joined: Oct 06, 2008
Posts: 10
Hi Every buddy
I am getting problem in ManyToOne Relationship.I am not getting that how to call entity.persist()from client.Because there will be two object of owing side class.
My proble is like this....

public class Person implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID", nullable = false)
private Long id;
@ManyToOne(cascade={CascadeType.ALL})

@JoinTable(name="Cu_Ad",
joinColumns={@JoinColumn(name="CustomerID")},
inverseJoinColumns={@JoinColumn(name="AddressID")})
private Address address=new Address();
...
}

public class Address implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID", nullable = false)
private BigDecimal id;
.....
}

Client Or servlet{

String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String city=request.getParameter("city");
String country=request.getParameter("country");

Address d=new Address();
d.setCountry(country);
d.setCity(city);

Pankaj p1=new Pankaj();
p1.setFirstname(fname);
p1.setLastname(lname);
p1.setAddress(d);

Pankaj p2=new Pankaj();
p2.setFirstname(fname);
p2.setLastname(lname);
p2.setAddress(d);

remote.CreateCruise(p1); remote.CreateCruise(p2);
}

My problem is i want in peson table two persons should be created whilw in Address table one value should go.
just please tell me wats worng in servlet class.
@OneToMany realtionship is working properly but this isn't.


I just want to create two pesons in person table & one address in Address table. please help me.........
Mark Garland
Ranch Hand

Joined: Nov 11, 2006
Posts: 226
Hi Panki,

I'm new to EJB so may not be able to help you.

If you have a ManyToOne relationship, that means that there are many entities owning the relationship to a single entity. In that case, why bother with a join table?
AFAIK, the join table is only required for the OneToMany relationship (where one entity owns a relationship to many others - but only has a single space in it's row).

MG


28/06/06 - SCJP - 69%, 05/06/07 - SCWCD - 92%, 28/02/08 - IBM DB2 v9 Fundamentals (Exam 730) - 87%, 18/11/08 - IBM DB2 v9 DBA (Exam 731) - 89%, 26/02/11 - SCBCD - 88%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @ManyToOne RelationShip
 
Similar Threads
inheritance and schema creation using JPA annotations
Bidirectional @OneToOne with JoinTable
JPA-Hibernate One-to-One Bidirectional Relationship issue
Why is my Hibernate Search query not working?
JPA data retrieval query