Always use primitive object wrappers for JPA @Id instead of primitive type?

人走茶凉 提交于 2019-11-30 05:10:37

I would say yes it is recommended to use object types instead of primitives because of the case you are seeing. There is no way of distinguishing if the entity is new or pre existing with a primitive identifier. I have used hibernate for years and I always use objects for identifiers.

I would use an object type. In the xml mapping, you could put an "unsaved-value" attribute, but i don't think there is a direct translation to the annotations for this. As a result, it's safer to stick with object types.

And most programmers would expect a "null" value in an identifier to mean unsaved anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!