Code:
public Object getObjectById(int objectId) throws EventManagerException {
Session session = getSessionFactory().getCurrentSession();
Event event = null;
try {
Transaction transaction = session.beginTransaction();
session.beginTransaction();
event = (Event) session.load(Event.class, Integer.valueOf(objectId));
} catch (Exception e) {
e.printStackTrace();
throw new EventManagerException(e);
}
return event;
}
for the sessions in spring I use: OpenSessionInViewFilter with singleSession=true
I subclassed it and overwrote two methods:
Code:
@Override
public void afterPropertiesSet() throws javax.servlet.ServletException {
setSingleSession(true);
}
public void closeSession(Session session, SessionFactory sessionFactory) {
if(!session.getTransaction().wasCommitted() && session.getTransaction().isActive()){
session.getTransaction().commit();
}
session.flush();
super.closeSession(session, sessionFactory);
}
Code:
@Entity
@Table(name = "event")
public class Event extends PersistentObject {
private Date startDate;
private Date endDate;
private Set<SubscriptionHistory> subscriptionHistories;
private Set<Question> questions;
private EventType eventType;
private String description;
private String title;
private String location;
private boolean isKnowledgeRelated = false;
private Date respondBefore;
private Person createdBy;
public boolean foo() {
return true;
}
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Version
@Column(name = "version")
public Integer getVersion() {
return this.version;
}
public void setVersion(Integer version) {
this.version = version;
}
..........
.........
}
I hope this is sufficient, if not please tell me and I'll provide you with other parts you require