Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

problem with onetomany

 
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
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your @JoinColumn should be on the ManyToOne, not on the OneToMany.

See,
http://en.wikibooks.org/wiki/Java_Persistence/OneToMany
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic