Java Reference
In-Depth Information
public Category create(String title) throws AdException {
try {
begin();
Category cat = new Category(title);
getSession().save(cat);
commit();
return null;
} catch (HibernateException e) {
rollback();
throw new AdException("Could not create the category", e);
}
}
public void save(Category category) throws AdException {
try {
begin();
getSession().update(category);
commit();
} catch (HibernateException e) {
rollback();
throw new AdException("Could not save the category", e);
}
}
public void delete(Category category) throws AdException {
try {
begin();
getSession().delete(category);
commit();
} catch (HibernateException e) {
rollback();
throw new AdException("Could not delete the category", e);
}
}
}
AdvertDAO provides all the methods required to delete an existing Advert object or create
a new Advert object (adverts are always retrieved by selecting them from a category, and are
thus indirectly loaded by the CategoryDAO class). Changes to the object in question will be per-
sisted to the database at the end of the transaction (see Listing 3-22).
Listing 3-22. The AdvertDAO Class for the Example
package sample.dao;
import org.hibernate.HibernateException;
Search WWH ::




Custom Search