Follows the steps below to setup S2Hibernate to use on Eclipse:
Extract files from the S2HibernateVx.x.x.jar distribution archive file.
Open an Eclipse workspace and import the extracted files as a Java project. Answer "yes" to all prompts asking whether you want to overwrite the .classpath. Sample files are included in the src/examples folder.
All jar files necessary to use S2Hibernate are in s2hibernate/lib folder.
Hibernate offers many implementations of connection pool and cache which may not be include in S2Hibernate. To use Hibernate features not included with S2Hibernate, download necessary software separately from the Hibernate site. HSQLDB RDBMS is included with S2Hiberate to allow developers to easily test database applications. To use HSQLDB, it is necessary to start the database. The database may be started by double clicking the runHsqldb.bat script file in the bin folder.
hsqldb.jar in lib folder is only necessary when using HSQLDB. If the production application does not use HSQLDB, hsqldb.jar is not required on the production server.
It is not necessary to set CLASSPATH to use S2Hibernate from Eclipse, but it is convenient to set the CLASSPATH of the following files to run S2Hibernate application from the command line.
files with jar extension in the lib file (hsqldb.jar is not necessary if HSQLDB is not used
A class that needs to use Hibernate needs to define S2SessionFactory type field and retrieve implementation class (S2SessionFactoryImpl) through constructor or through deployment. Then, Hibernate functions may be used by calling S2SessionFactory.getSession() method and obtaining a S2Session object, which is a wrapper to Hibernate Session object. Methods supported by Hibernate Session object may be called through this S2Session.
S2Session converts HibernateException into HibernateRuntimeException so a class that does not need to catch HibernateException does not require a catch clause.
It is not necessary to explicitly open and close session and to control transactions. To catch error exception, catch HibernateRuntimeException and call the getCause() method to get HibernateException.