Home JPA: ignore field on select, but update(Hibernate Save or Update)
Reply: 0

JPA: ignore field on select, but update(Hibernate Save or Update)

Learner
1#
Learner Published in 2017-12-06 13:14:33Z

I've a situation where I need to save or update user data but not want to include one field while fetching(lastUpdateTime). But while updating the row, I want to update the row if any changes are there with the lastUpdateTime column.

I saw other posts and came to know that updatable=false is the way to exclude update, but is there anything which is like 'selectable=false' or something like this?

Thanks for the help in advance.

Save Or Update Code

public void insertData(Table obj) {
    Session session = DbConnectionFactory.getSessionFactory().openSession();
    Transaction tx = null;
    try {

        tx = session.beginTransaction();
        session.saveOrUpdate(obj);
        tx.commit();

    } catch (Exception ex) {
        ex.printStackTrace();
        if (tx != null)
            tx.rollback();
        // _log.error(ex,ex);
        obj = null;
        logger.log(Level.SEVERE, "Failed to Insert into Table");
    } finally {
        if (session != null) {
            session.clear();
            session.close();
        }

    }

Code Used to Insert Data

insertData(objectList.get(i));

objectList contains the lastUpdateTime as well.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 3.313015 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO