Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with onetomany

 
enrique sime
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 553
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic