Let us say there is a Teacher object which Instructors holds a listing of Courses objects. The classes for the Teacher can alter. Some get added, some get erased. What's a great way to update this alterations in the database. 1. Immediately after every change, update the database. e.g.: A training course get added, immediately include that in to the database too . 2. In the end changes are created to the entity/object Teacher (classes are added, classes are erased), only then update the database with the changes. 3. Others ??
I can tell for 1 and a pair of pros and cons. For 1: I'm not sure how good it's when data designs include direct accessibility database. For Just Two: The formula its more complicated because you need to compare the data within the data models with information within the database all at one time.
Have a look at a few of the ORM tools readily available for a foreign language or platform. An object's representation of the entity within the database can invariably escape-of-sync. For instance, if your user transformed a particular property, along with a database update was attempted however for whatever reasons that update unsuccessful. Now both of these products aren't synchronized.
This may also rely on the regularity of updates for your database. If you do not expect massive activity when it comes to creates towards the database, triggering instant database updates on any property change might be a choice.
Otherwise, you might incorporate a
dirty flag inside your resist indicate if this is out of sync using the database. Object changes might be up-to-date because they happen, or whenever a event is triggered for example once the user decides in order to save their progress, or periodically, say every x minutes.
Different languages and frameworks implement these model objects in a different way. In Rails, one object is subclasses from ActiveRecord and understands how to persist itself right into a database. In Java, you'd rarely mix domain objects using the way they are endured. That's usually taken proper care of by an ORM framework or custom DAO objects.
I discovered about Hibernate. It's precisely what i want and it is simple.