Mapear List JPA / Hibernate

31 views
Skip to first unread message

Mauricio Ferreyra

unread,
May 18, 2009, 1:47:29 PM5/18/09
to JavaSOS
Tengo un problema al mapear un List en JPA usando Annotationes
Hibernate.

Estos son mis objetos :

@Entity
@Table(name = "articulos")
public class Articulo implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "art_id")
private Long id;

@org.hibernate.annotations.CollectionOfElements(targetElement =
FotoArticuloWeb.class,fetch=FetchType.EAGER)
@JoinColumn(name = "art_id")
private List<Foto> fotos;

/* Setters and Getters */

}

@Entity
@Table(name = "fotos")
public class FotoArticuloWeb implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "fot_id")
private String fawCodigo;

/* Setters and Getters */

}

El problema es que cuando obtengo los articulos me trae un articulo
por cada foto que tiene en la BD, es decir, en la BD tengo un solo
articulo con muchas fotos y me trae tantos objetos del tipo Articulo
como fotos tenga el mismo.

Que esta mal del mapeo?

Gracias

Mauricio.

Pablo Ruggia

unread,
May 19, 2009, 3:45:38 PM5/19/09
to jav...@googlegroups.com
En vez de @CollectionOfElements usa @OneToMany.
Si todavia seguis teniendo el mismo problema manda como traes los objetos, query, load, etc.

Saludos !

Mauricio Ferreyra

unread,
May 20, 2009, 10:38:40 AM5/20/09
to jav...@googlegroups.com
Agregue el filtro OpenSessionInViewFilter en mi web.xml y funciono!!


2009/5/19 Pablo Ruggia <pru...@gmail.com>
Reply all
Reply to author
Forward
0 new messages