I tried so far the below code:
Session session = null;
Query query1 = null;
Query query2 = null;
String[] parts = userId.split("=");
userId = parts[1];
parts = userId.split(" ");
userId = parts[0];
int intIdUser = Integer.parseInt(userId);
try {
session = getSession();
UserCountry userCountry = new UserCountry();
UserLanguage userLanguage = new UserLanguage();
for (String s : user_country) {
userCountry.setUserId(intIdUser);
userCountry.setCountryId(Integer.parseInt(s));
session.getTransaction().begin();
session.persist(userCountry);
session.getTransaction().commit();
}
for (String s : user_language) {
userLanguage.setUserId(intIdUser);
userLanguage.setLanguageId(Integer.parseInt(s));
session.getTransaction().begin();
session.persist(userLanguage);
session.getTransaction().commit();
}
}
catch(Exception e) {
logger.error("Exception while fetching for countryId: "+userId, e);
throw new PlRuntimeException(e.getMessage());
}
finally {
if(session !=null)
session.close();
}
But the for (String s : user_country) and for (String s : user_language) loops are saving just first element on the list user_country and user_language.
How to make it save the other elements on the list?
Thanks for advice.