With Hibernate, it's as simple as loading a set of records and then manipulating the data:
Code:
public static void updateAll() {
AnnotationConfiguration config =
new AnnotationConfiguration();
config.addAnnotatedClass(User.class);
SessionFactory factory;
factory = config.configure().buildSessionFactory();
Session session = factory.getCurrentSession();
session.beginTransaction();
java.util.List allUsers;
System.out.println("Updating all records...");
Query queryResult = session.createQuery("from User");
allUsers = queryResult.list();
System.out.println("# of rows:"+allUsers.size());
for (int i = 0; i < allUsers.size(); i++) {
User user = (User) allUsers.get(i);
System.out.println(user);
user.setPassword("password");
session.update(user);
}
System.out.println("Database table updated...");
session.getTransaction().commit();
}
If you're doing many records, you might want to look at ETL tools as perhaps a better solution. Just straight batch isn't always best performed with Hibernate.