I tried inserting data into the database using the controller by obtaining the parameters as a HttpRequest and then invoking the service class which in turn invokes the dao class.
Would like to know how do i proceed to insert data into the database
Hi @sharonvarghese
I’m not able to get a clear picture of where the issue is. So I’ll just elaborate on how I added database connectivity to the OAuth2 module.
You can use @transactional annotation in your Service Layer to ensure that transactional AOP takes care of opening and closing sessions for the Hibernate Session Factory.
eg :
Then, In the DAO methods, you can get an instance of the sessionFactory bean by autowiring.
Once you have that, you can use sessionFactory.saveOrUpdate(Object), sessionFactory.get(Integer) etc methods exposed by the Hibernate Session Factory to interact with the MySQL database or H2 database (when testing).
DAO example :