Announcement Announcement Module
Collapse
No announcement yet.
Code not saving changes to database. (very frustrating) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code not saving changes to database. (very frustrating)

    Code:
    	@SuppressWarnings("unchecked")
    	//@Override
    	public SerialNumber getCounter(String id) {
    		Session cs = sessionFactory.getCurrentSession();     
    		SerialNumber sn = (SerialNumber) cs.get(SerialNumber.class, id);
    		if (sn == null) {
    			//TODO Throw an error (maybe). The code below creates a new Serial number counter
    			log.debug("NO Serial Number for: " + id + " was found.");
    			sn = new SerialNumber();
    			sn.setSerialNumberId(id);
    			sn.setName("Unspecified");
    			sn.setValue(0);
    		}
    		sn.setValue(sn.getValue()+1);
    		cs.saveOrUpdate(sn);
    		cs.close();
    		return sn;
    	}
    This line seems to be ignored:

    Code:
    		cs.saveOrUpdate(sn);
    After this line, I would assume the database is updated but this is not the case. What am I doing wrong?

    Thanks.

  • #2
    Please use the search as this question has been answered numerous times before.

    To insert/update/delete data in the database you need transactions, without a transaction your insert/update/delete statement is useless. Also don't mess around with the session yourself, don't close it let spring handle that for you (that is why you want to use springs transaction management).

    Comment

    Working...
    X