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 "}".

Environment

N/A

Activity

Show:
Jack C. Holt
July 13, 2006, 8:54 PM

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

Jack C. Holt
July 13, 2006, 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;
}

Christian Bauer
July 21, 2006, 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.

Steve Ebersole
March 21, 2011, 7:04 PM

Bulk closing stale resolved issues

Won't Fix

Assignee

Unassigned

Reporter

Jack C. Holt

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure