Sobhan
Sobhan

Reputation: 1460

Update a list of entity using Hibernate in Java

I get a list of entity from database using the code below:

List<NeginHotData> neginHotData = getNeginHotDataByStatus(null);

Then i need to change the Status field of them from NULL to "Active" and that's OK, the problem is that ,Is it possible to do this without iterating through the list of objects and updating them one by one? That doesn't sound efficient to me. I need a solution to update them completely with each other because i have about 7000 record and iterating through the list of objects and updating them one by one isn't really a good solution .

Upvotes: 0

Views: 1089

Answers (1)

user10639668
user10639668

Reputation:

You can use HQL like this:

    String hqlUpdate = "update NeginHotData c set c.status = :status where c.bla= :bla"; 
    int updatedEntities = s.createQuery( hqlUpdate ).setString( "bla", bla).setString( "status", status).executeUpdate(); 

This works only if you set the same status for all entities involved.

Upvotes: 1

Related Questions