Updating (in MySQL database) Java objects with changed primary keys -


i'm sorry if title misleading.

i have objects represent database entries, use reflection , annotations automatically retrieve/save objects from/to database. wondering how handle changes primary keys of objects. problem original "values" not remembered @ moment.

example:

@dbclass(tablename="category") public class category {      @dbfield(name="caregory_name", isprimarykey = true)     public string categoryname;      @dbfield(name="a_value", isprimarykey = false)     public double avalue; } 

then function datbaseoperations.sotreobject(category.class, acategoryinstance) tries create proper prepared statement , store (update) object basing on annotations.

but if change categoryname field, cannot create proper sql statement (update category set categoryname = ... <- don't remember original value)

i emphasise need solution working whole reflection/annotations approach.

i thinking of creating interface like:

public interface hasoriginal {     public object original = null; } 

and implement database-related classes it. when database object created, copy original object , store original form.

any comments please? better ideas?


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -