Bom dia Pessoal , Estou tento um problema com Hibernate .
Tentando implementar um genericDao , aparentemente não estou conseguindo manter minhas sessões ou algo do tipo.
se alguem já passou por isso : o erro
INFO: table found: Libifsp.books
18/02/2012 09:28:00 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [author, title, publishinghouse, pages, isbn, score, identifier]
18/02/2012 09:28:00 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
18/02/2012 09:28:00 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
18/02/2012 09:28:00 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Exception in thread "main" java.lang.StackOverflowError
at br.com.mauricio.libraryIFSP.dataBase.BookDao.save(BookDao.java:11)
at br.com.mauricio.libraryIFSP.dataBase.BookDao.save(BookDao.java:11)
at br.com.mauricio.libraryIFSP.dataBase.BookDao.save(BookDao.java:11)
Classe BookDao e meu metodo save:
public class BookDao extends GenericDao<Book> implements IBookDao {
@Override
public void save(Book bookForSave) {
save(bookForSave);
}
}
Classe Generic DAO e meu metodo generic Save:
public class GenericDao<T extends Serializable> {
private final Session session;
private final Class<T> persistentClass;
private final Transaction transaction;
@SuppressWarnings("unchecked")
public GenericDao() {
this.session = HibernateUtil.getSession();
this.transaction = session.beginTransaction();
this.persistentClass = (Class<T>) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
public Session getSession() {
return session;
}
public Transaction getTransaction() {
return transaction;
}
protected void save(T entity) {
try {
getSession().getTransaction().begin();
getSession().save(entity);
getSession().getTransaction().commit();
} catch (Throwable t) {
getSession().getTransaction().rollback();
t.printStackTrace();
} finally {
close();
}
}
}
e minha classe HIbernate Util
public class HibernateUtil {
private static SessionFactory SESSION_FACTORY;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
SESSION_FACTORY = new AnnotationConfiguration().configure(
"hibernate.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession() {
return SESSION_FACTORY.openSession();
}
}
Agradeço desde já a ajuda de todos , creio que seja um problema simples mais estou tentando a algum tempo já , sem sucesso...
VLW
s'