Hi!
I load just, for example 3 columns (a,b,c) from my table(A) - which also contains more columns like x,y,z.
now i wanna load just these 3 columns:
Code:
public static List<A> readBatchData() {
Session session = HibernateUtil.getCurrentSession();
Transaction tx = null;
ArrayList<A> values = null;
try {
tx = session.beginTransaction();
/* read special columns from db */
values = (ArrayList<A>)session.createQuery
(select new A(a,b,c) from A).list();
/* commit and close session */
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
} finally {
session = null;
tx = null;
}
return values;
}
Then i update the data and then i wanna update these colums at the database table:
Code:
public static void updateBatchData(final List<A> updateList) {
Session session = HibernateUtil.getCurrentSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
for (A model : updateList) {
/* update */
session.saveOrUpdate(model);
}
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
} finally {
session = null;
tx = null;
}
}
But if i do it like that, then the other columns (x,y,z) will be set NULL - any solutions?
Second question:
when
Code:
session.saveOrUpdate(model);
get called thats already a database interaction (columns get set at db?) or the model got saved at the hibernate session until
Code:
tx.commit()
get called?
best regards.