Is there any available API to represent various units of item like KG, Litre, Metre, KM, etc

前端 未结 2 987
故里飘歌
故里飘歌 2021-01-01 22:27

In my project, somewhere I have to work with a unitOfIssue of Items. Now, various items of course can have different units of representation. So, I

相关标签:
2条回答
  • 2021-01-01 23:15

    I was in a project in which we had extensive use of JSR-275 (before it was rejected by JCP). Originally we were not using JPA, but later it was decided that we should persist our model using JPA 2.0 and I had to deal with the persistence of my measure objects.

    This may not be the answer to your question, but may bring some interesting thoughts to the discussion.

    We considered several alternatives:

    1. Measures were serializable, and JPA can map any serializable object. The problem here is that the measures would be saved as binary objects in the database and they'd be subject to all the issues of serialization (i.e. versioning, etc.)
    2. We could adapt our model by keeping the data in raw types (i.e. integers, double, etc) provided that we agree on using the international unit of measure for every unit. Thus, fields would be based in JPA-supported types, but getters and setters would use measure objects. Configure JPA mapping to be based on fields, not properties. The problem here was having to alter the model to change encapsulated data without affecting the public interface of the domain objects.
    3. Since we were using hibernate as our persistence provider, we could accept to deviate from the JPA standard and use hibernate custom value types to map measure objects to ther corresponding primitive types. Then we could map our types using hibernate annotations for this purpose. (See an example here). The caveat in this one is losing persistence vendor independence.

    We ended up using alternative #3 and it worked pretty well for us.

    0 讨论(0)
  • 2021-01-01 23:19

    I suggest you to write your own. Probably you may need Unit Of Measure Conversion also.

    Definition of UOM from ARTS Retail Data Model Logical View

    enter image description here

    and for conversion

    enter image description here

    0 讨论(0)
提交回复
热议问题