My client wrote the back-end for an application i’m building using PHP. However He didn’t write the database all too well. For instance there is two tables one ‘users’ and one ‘user_settings’. However his script would only create rows in ‘user_settings’ once a user decided to modify their settings. Otherwise his entire script used defaults, in his words “as an attempt to save database space”.
However, in Hibernate i’m having to try and get those ‘user_settings’ for some users and its causing problems for those that don’t have any set. Is there a way in hibernate that I would be able to insert some default settings into the database, after a call to getClientSettings() if nothing exists in the database for that client?
I dont know how exactly you have implemented the retrieval function , but one way i can suggest is you should try to retrieve the user_settings as an object, if the object is null then you can create a new instance of the mapped class (say user_settings) , set the key which is common (something like userId) , and then set other default values and then store the object in DB, this way your application would work without exceptions and defaults values will also get populated.