File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "problem with onetomany" Watch "problem with onetomany" New topic

problem with onetomany

enrique sime

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

public class Cliente implements Serializable {

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

public Cliente() {

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

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

public class Articulo implements Serializable {

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

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.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
I agree. Here's the link:
subject: problem with onetomany
It's not a secret anymore!