Hibernate gets an object by non-primary key and updates it + Spring mvc

When I retrieve an object using its id and I change its properties and update it everything works fine, but when I retrieve my objects using their name + version and update them, none of the changes are saved to the database. Could you please let me know what the problem is?

// Get by id

public PdfDocument get(Long id) {
    return (PdfDocument) session().get(PdfDocument.class, id);
}

      

// Get by name + version

public PdfDocument get(String name, int version) {
    Criteria criteria = session().createCriteria(PdfDocument.class);
    criteria.add(Restrictions.eq("name", name));
    criteria.add(Restrictions.eq("version", version));
    return ((PdfDocument) criteria.uniqueResult()) ;
}

      

// update

public void update(PdfDocument PdfDocument) {
    session().saveOrUpdate(PdfDocument);
}

      

+3


source to share


1 answer


Can be a criterion returning a different entity than your pending one. Check the id of the returned object and expected.



0


source







All Articles