public static void main(String[] args) {
UserDaoHibernate userProfileDaoHibernate = new UserDaoHibernate();
userProfileDaoHibernate.setSessionFactory(HibernateUtil
.getSessionFactory());
UserDao userProfileDao = userProfileDaoHibernate;
Transaction tx = HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction();
try {
// Register user.
User userProfile = new User("user@udc.es",
PasswordEncrypter.crypt("userPassword"), "name",
"lastName", "user");
userProfileDao.save(userProfile);
Long userId = userProfile.getUserId();
System.out.println("User with userId '" + userId
+ "' has been created");
System.out.println(userProfile);
// Find user.
userProfile = userProfileDao.find(userId);
System.out.println("User with userId '" + userId
+ "' has been retrieved");
System.out.println(userProfile);
// ... proceed in the same way for other entities / methods / use