wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes problem with onetomany Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "problem with onetomany" Watch "problem with onetomany" New topic
Author

problem with onetomany

enrique sime
Greenhorn

Joined: Jan 07, 2012
Posts: 1
please help me im new with jpa and im trying to use onetomany relacion but it does not work because im trying to get the id of the client in my field id_cliente in the articulo entity

@Entity
public class Cliente implements Serializable {

private static final long serialVersionUID = 1L;
@Id
private String id;


public Cliente() {
}

public Cliente(String id, String nombre) {
this.id = id;
this.nombre = nombre;
}
private String nombre;

@OneToMany(mappedBy="cliente",cascade= CascadeType.ALL)
@JoinColumn(name="id_cliente")
private List<Articulo> articulos ;
//setters and getters


@Entity
public class Articulo implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String descripcion;
private double precio;
private String fecha_Inicial;
private String fecha_Vencimiento;
private int quincenas;
@ManyToOne()

private Cliente cliente;

public Articulo() {
}

public Articulo(String descripcion, Double precio) {
this.descripcion = descripcion;
this.precio = precio;
this.fecha_Inicial = fecha_Inicial;
this.fecha_Vencimiento = fecha_Vencimiento;

}
//setters and getters
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Your @JoinColumn should be on the ManyToOne, not on the OneToMany.

See,
http://en.wikibooks.org/wiki/Java_Persistence/OneToMany

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
 
subject: problem with onetomany
 
Similar Threads
Passing parameters with h: link
Multiple Column Join
nullPointerException on entity manager methods
JPA - need help with query
EJB - Everything works except persist()