Finding : Enities not getting persisted with Seam
Seam helps to quickly setup a enterprise web project. You can just configure different services like database operations, security and start with your business logic. I have created a small CRUD application. But I have faced this strange problem with persisting entities. Here I will explain, how I have solved it.
I have following code in my project
I have configured hibernateSession in my components.xml as following
<persistence:hibernate-session-factory name="hibernateSessionFactory" />
<persistence:managed-hibernate-session name="hibernateSession" session-factory="#{hibernateSessionFactory}"
auto-create="true" />
And in one of the seam component I have a method to create a new user which looks like as follows
public void createNewUserInDatabase(){
User user = new User("Ganesh","Gembali");
hibernateSession.persist(user);
}
Following code getting executed with out any stacktrace. But I could not find this new entry in my database. After checking with the seam manual and community forums, its because of missing Transactional annotation for the method. So you must use transactional annotation when you want to persist using seam managed hibernate session.
@Transactional
public void createNewUserInDatabase(){
User user = new User("Ganesh","Gembali");
hibernateSession.persist(user);
}
Any suggestions are always welcome. Stay tuned for more Seam findings and tips
.