Cannot Insert Data into the database

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

Thank you

Looking into http://en.flossmanuals.net/openmrs-developers-guide/hello-world-module/ would be of help, you may be interested in saving time by replacing Hibernate ORM (*.hbm.xml) file with Annotations as at:

Thanks a lot :slight_smile:

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 :

Hope that helps :smiley:

1 Like

Here is another example that seems to touch all the like files you need to touch:

Otherwise, give more details on what you tried! and where you are stuck from

2 Likes

trying it out now. thank you :slight_smile:

1 Like