{"action":"closed","issue":{"url":"https://api.github.com/repos/abraxas-labs/ameba-lib/issues/77","repository_url":"https://api.github.com/repos/abraxas-labs/ameba-lib","labels_url":"https://api.github.com/repos/abraxas-labs/ameba-lib/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/abraxas-labs/ameba-lib/issues/77/comments","events_url":"https://api.github.com/repos/abraxas-labs/ameba-lib/issues/77/events","html_url":"https://github.com/abraxas-labs/ameba-lib/issues/77","id":153667848,"number":77,"title":"Extend base entity class to provide application assigned id","user":{"login":"openwms","id":246873,"avatar_url":"https://avatars.githubusercontent.com/u/246873?v=3","gravatar_id":"","url":"https://api.github.com/users/openwms","html_url":"https://github.com/openwms","followers_url":"https://api.github.com/users/openwms/followers","following_url":"https://api.github.com/users/openwms/following{/other_user}","gists_url":"https://api.github.com/users/openwms/gists{/gist_id}","starred_url":"https://api.github.com/users/openwms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openwms/subscriptions","organizations_url":"https://api.github.com/users/openwms/orgs","repos_url":"https://api.github.com/users/openwms/repos","events_url":"https://api.github.com/users/openwms/events{/privacy}","received_events_url":"https://api.github.com/users/openwms/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/abraxas-labs/ameba-lib/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/abraxas-labs/ameba-lib/milestones/20","html_url":"https://github.com/abraxas-labs/ameba-lib/milestones/1.6","labels_url":"https://api.github.com/repos/abraxas-labs/ameba-lib/milestones/20/labels","id":1753758,"number":20,"title":"1.6","description":"","creator":{"login":"openwms","id":246873,"avatar_url":"https://avatars.githubusercontent.com/u/246873?v=3","gravatar_id":"","url":"https://api.github.com/users/openwms","html_url":"https://github.com/openwms","followers_url":"https://api.github.com/users/openwms/followers","following_url":"https://api.github.com/users/openwms/following{/other_user}","gists_url":"https://api.github.com/users/openwms/gists{/gist_id}","starred_url":"https://api.github.com/users/openwms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openwms/subscriptions","organizations_url":"https://api.github.com/users/openwms/orgs","repos_url":"https://api.github.com/users/openwms/repos","events_url":"https://api.github.com/users/openwms/events{/privacy}","received_events_url":"https://api.github.com/users/openwms/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":2,"state":"open","created_at":"2016-05-08T17:35:22Z","updated_at":"2016-06-02T17:36:47Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-05-08T17:34:56Z","updated_at":"2016-06-02T17:36:47Z","closed_at":"2016-06-02T17:36:47Z","body":"Currently the `BaseEntity` class has already an `id` field, that is assigned by the persistence provider and used as primary key column. The value of this database dependent key is often passed as id over public APIs. Under the following circumstances this may lead to problems:\r\n\r\n- Database migration: Whenever a database migration takes place, the PKs may change. Depends on migration mechanism (dump vs. script). I've although seen that a data storage of a microservice has been migrated from MongoDB to RDBMS, the key type changed from `String` to `Long`. All this may lead to problems whenever a client application keeps track of data offline \r\n- Versioning is enabled: A referenced entity has been updated technically several times by backend services (no semantical or logical change). Therefore the primary key value has changed, too. A client does not know or care about these technical changes due to versioning and wants to call the API with the id retrieved before.\r\n\r\n**Solution**\r\nExtend the `BaseEntity` class and add an application assigned id (server assigned - not client assigned). This id column shall be unique on the table and be set whenever the entity is persisted the first time. It is not going to be changed afterwards! Where the primary key field is called `pk` this field should be named `id`. Aside property definition, the subclass although defined the unique constraint on the new column for all inherited entity classes.\r\n\r\n**References**\r\nI've used a similar approach with [GraniteDS](http://www.graniteds.org), where a GUID is used as an application assigned id and that is on `PrePersist`. See [http://www.graniteds.org/public/docs/latest/docs/reference/flex/graniteds-refguide-flex.html#data.jpamanaged](http://www.graniteds.org/public/docs/latest/docs/reference/flex/graniteds-refguide-flex.html#data.jpamanaged)"}}
{"actor":{"display_login":"openwms"}}