02/08/2013, 06:48
|
| | Fecha de Ingreso: julio-2012 Ubicación: Madrid
Mensajes: 5
Antigüedad: 12 años, 6 meses Puntos: 0 | |
Respuesta: Error aplicación web struts2-spring-hibernate Continuo aqui: ListingEventos.java
Código:
package com.app.struts.actions.eventos;
import com.app.struts.actions.base.BaseAction;
import com.app.model.Evento;
import com.app.service.IEventoService;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
public class ListingEventos extends ActionSupport {
protected IEventoService serviceEvento;
@Override
public String execute() throws Exception
{
eventos = serviceEvento.getEvents();
return "success";
}
List<Evento> eventos;
public List<Evento> getEvents() {
return eventos;
}
public void setServices(IEventoService value) {
serviceEvento=value;
}
}
EventoServiceImpl.java
Código:
package com.app.service;
import com.app.model.Evento;
import com.app.dao.IEventoDAO;
import java.util.List;
public class EventoServiceImpl implements IEventoService{
private IEventoDAO dao;
public EventoServiceImpl(IEventoDAO dao) {
this.dao = dao;
}
public Evento getEventById(long id){
return dao.getEventById(id);
}
public boolean deleteEventById(long id) {
return dao.deleteEventById(id);
}
public void createEvent(String name) {
dao.createEvent(name);
}
public List<Evento> getEvents(){
return dao.getEvents();
}
public void removePersonFromEvent(int personId, int eventId){
dao.removePersonFromEvent(personId, eventId);
}
public void addPersonToEvent(int personId, int eventId){
dao.addPersonToEvent(personId, eventId);
}
}
EventoDAOImpl.java
Código:
package com.app.dao;
import com.app.model.Evento;
import com.app.service.IArtistaService;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessException;
public class EventoDAOImpl implements IEventoDAO {
private SessionFactory sessionFactory;
public EventoDAOImpl(SessionFactory sessionFactory){
this.sessionFactory = sessionFactory;
}
public Session sess() {
return sessionFactory.getCurrentSession();
}
public Evento getEventById(long id){
Query query = sess().createQuery("from com.app.model.evento e where e.id = :ID ");
//query.setString("ID",Evento.getId());
Evento EventoOut = (Evento)query.uniqueResult();
return EventoOut;
//return (Evento) sess().load(Evento.class, id);
}
public boolean deleteEventById(long id)
throws DataAccessException {
sess().delete(getEventById(id));
return true;
}
public void createEvent(String name) {
Evento theEvent = new Evento();
theEvent.setName(name);
sess().save(theEvent);
}
@SuppressWarnings("unchecked")
public List<Evento> getEvents() {
return sess().createQuery("from com.app.model.evento").list();
}
private IArtistaService iArtistaService;
public void removePersonFromEvent(int personId, int eventId){
getEventById(eventId).getPeople().remove(iArtistaService.getPersonById(personId));
}
public void addPersonToEvent(int personId, int eventId) {
getEventById(eventId).getPeople().add(iArtistaService.getPersonById(personId));
}
}
Evento.java
Código:
package com.app.model;
import java.util.Set;
import com.app.model.Artista;
public class Evento {
Long id;
public Long getId()
{return id;}
public void setId(Long id)
{this.id = id;}
String name;
public String getName()
{return name;}
public void setName(String value)
{name = value;}
Set<Artista> people;
public void setPeople(Set<Artista> people)
{this.people = people;}
public Set<Artista> getPeople()
{return people;}
}
Evento.hbm.xml
Código:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.app.model.Evento" table="events">
<id name="id" column="Id">
<generator class="increment">
</generator>
</id>
<!--property name="dt" /-->
<property name="name" />
</class>
</hibernate-mapping>
|