Search code examples
javaormlite

Ormlite ignore field when calling createOrUpdate


Is there an annotation that I can apply to a field that when calling createOrUpdate and passing the object that the specific field will not be updated if the object already exists. The use case is I have a creation date in my object (which is set to current time of Java object creation) but if the object already exists in the database I do not want the date to be updated but would want the other fields updated. Would it be better to do a query on the id (create if it doesn't exist) and then in my code just iterate through the other fields and do updates for any that are different.


Solution

  • Is there an annotation that I can apply to a field that when calling createOrUpdate and passing the object that the specific field will not be updated if the object already exists.

    Hrm. No there isn't. One thing you could do is create a class which has the same fields but without the date field. Or you could have a base-class with all of the fields except the date field. Then have a sub-class which adds the date field. Both classes would save to the same table. You would save the one with the date object when you want to use it.

    Hope this helps.