Here's where I'm stuck:
javax.servlet.ServletException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: it.trew.model.TipoCaratteristica.traduzioni, no session or session was closed
Some of my entities code:
@Entity
@Table(name = "tipi_caratteristiche")
public class TipoCaratteristica implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
private String nome;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "tipi_caratteristiche_traduzioni",
joinColumns = { @JoinColumn(name = "tipo_caratteristica_id") },
inverseJoinColumns = { @JoinColumn(name = "traduzione_id") }
)
private List<Traduzione> traduzioni = new ArrayList<Traduzione>();
"Traduzione" is a simple plain entity with a pair of String properties.
I have an "edit" jsf page which loads a "TipoCaratteristica" by id and try to show its List in a tag.
I use an ejb-facade method for fetching the edited object:
public T find(Object id) {
return getEntityManager().find(entityClass, id);
}
Then, in the jsf backing bean:
TipoCaratteristica tc = ejbFacade.find(Long.valueOf(value));
I read something about that exception. Actually, setting fetch type EAGER on the "traduzioni" collection fix it but I don't want to. I read about doing all in a transaction, or using Hibernate.initialize() but don't know how to do that.
Can you help me please?