I have question. Is it possible to create new entry in the db if the entry does not exist? If it exist it should update the current entry.
I have something like this:
@Transactional
public void saveSettingsForUser(String userId, SettingsMessageModel settings) {
Session session = getSessionFactory().getCurrentSession();
UserSettings userSettings = new UserSettings();
userSettings = (UserSettings) session.load(UserSettings.class, userId);
userSettings.setUserId(userId);
userSettings.setAutoanswer(settings.isAutoanswer());
userSettings.setDnd(settings.isDnd());
session.save(userSettings);
}
It works for entries that are already in the db. But if I want to save new one with primery key userId it does not allow me. Any suggestion is appreciated. Thank you!