Announcement Announcement Module
Collapse
No announcement yet.
Correct approach: Spring, Hibernate, ModelAndView Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Correct approach: Spring, Hibernate, ModelAndView

    Hi,
    I have been tasked with reworking the backend of our system to make it support multiple users. Currently the Dao layer is committing on every single action and we need it to track changes over a set of user actions (selecting, editing, saving). Rather than saving the instant you edit something.

    Currently we have ModelandViews on specific urls.
    These directly access the daos which are annotated @Transactional, which i believe makes the methods in the dao operate as transactions, so each get,save,update.
    The daos relate to data which are @Table marked and use named queries.

    My planned approach is to:
    Place a @Service layer in between the Controllers (which return the ModelandView) and the Dao. I'll make the Service @Transactional and remove @Transactional from the DAO.
    Then in the service I will do code like:
    getCurrentSession()
    session.beginTransaction()

    //do stuff

    commitTransaction.

    Then at the commit stage we get database errors if 2 users have clashed causing one to rollback.

    Is this the correct approach? I've tried to modify a unit test to check this but had issues getting Thread objects I create to actually be wired up to have different sessions.

    Regards,
    Iain
Working...
X