Hello guys
I'm losing several nights with this problem
There are are many questions of same type, but none works for me.
someone could help me, please?
I have JSF Hibernate application
TeamModel
Code:
@Entity
@Table(name="team")
public class Team implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id_team",nullable=false)
private Integer idTeam;
@Column(name="team",nullable=false)
private String team;
@OneToMany(fetch=FetchType.LAZY, targetEntity=Usuario.class,mappedBy="team")
private Set usuarios = new HashSet(0);
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="id_flm")
private Flm flm;
---------------------
TeamDaoImpl
Code:
@Override
public void atualizar(Team team) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
session.update(team);
session.beginTransaction().commit();
} catch (Exception e){
System.out.println("Erro ao inserir: "+e.getMessage());
session.beginTransaction().rollback();
} //finally {
//session.close();
//}
}
@Override
public Team findById(Integer id_team) {
Session session = HibernateUtil.getSessionFactory().openSession();
return (Team) session.load(Team.class, id_team);
}
@Override
public List<Team> findAll() {
Session session = HibernateUtil.getSessionFactory().openSession();
return session.createQuery("from Team ORDER BY id_flm ASC").list();
}
---------------------
TeamBean
Code:
@ManagedBean(name="teamBean")
@ViewScoped
public class TeamBean implements Serializable {
---------------
FlmDaoImpl
Code:
public class FlmDaoImpl implements FlmDao {
@Override
public List<Flm> selectItems() {
List<Flm> listado = null;
Session sesion = HibernateUtil.getSessionFactory().getCurrentSession();
String sql = "FROM Flm";
try {
sesion.beginTransaction();
listado = sesion.createQuery(sql).list();
sesion.beginTransaction().commit();
} catch (Exception e) {
sesion.beginTransaction().rollback();
System.out.println("Erro no selecItemsFLM: "+e.getMessage());
}
return listado;
}
Note: merge() works only when update "team name" field, does not work to "flm" field