Incorrect code in Hibernate 3.1.1 Reference PDF

Description

the last code snippet in section 1.3.3 on page 13 shows the following code:

Long eventId = mgr.createAndStoreEvent("My Event", new Date());
Long personId = mgr.createAndStorePerson("Foo", "Bar");

Both methods are defined as returning void, not Long. Therefore, the code causes a compiler error.

The code snippet is also missing a closing "}".

Activity

Steve EbersoleMarch 21, 2011 at 7:04 PM

Bulk closing stale resolved issues

Christian BauerJuly 21, 2006 at 8:40 AM

1. That is why the tutorial includes that statement just before the code snippet: "you might have to modify some of the previous methods to return that identifier"

2. The included tutorial source code includes this modified code ready for copy/paste.

3. The missing } has been fixed.

Jack C. HoltJuly 13, 2006 at 9:15 PM

I suggest that the following method be modified as follows:

private Long createAndStoreEvent(String title, Date theDate) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);
session.save(theEvent);
Long eventId = theEvent.getId();
session.getTransaction().commit();
return eventId;
}

... and that the following method be added.

private Long createAndStorePerson(String firstName, String lastName) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Person thePerson = new Person();
thePerson.setFirstname(firstName);
thePerson.setLastname(lastName);
session.save(thePerson);
Long personId = thePerson.getId();
session.getTransaction().commit();
return personId;
}

Jack C. HoltJuly 13, 2006 at 8:54 PM

Actually, createAndStorePerson() was never defined at all in the tutorial

Won't Fix

Details

Assignee

Reporter

Components

Affects versions

Priority

Created July 13, 2006 at 8:49 PM
Updated March 21, 2011 at 7:04 PM
Resolved July 21, 2006 at 8:40 AM