JPA property java.net.URL

后端 未结 2 1135
无人及你
无人及你 2020-12-16 17:05

HI,

I have an object which has a piece of URL-Information associated with it. Currently I save this URL in a simple String property, but java.net.URL would provide

2条回答
  •  -上瘾入骨i
    2020-12-16 17:44

    As per the JPA spec:

    The persistent fields or properties of an entity maybe of the following types: Java primitive types; java.lang.String; other Java serializable types (including wrappers of the primitive types, java.math.BigInteger, java.math.BigDecimal, java.util.Date, java.util.Calendar[7], java.sql.Date, java.sql.Time, java.sql.Timestamp, user-defined serializable types, byte[], Byte[], char[], andCharacter[]); enums; entity types and/or collections of entity types; and embeddable classes (see section 2.1.5).

    Plus the support for collections. But no primitive support of URL. They would however be supported as Serializable, which I guess would result in a LOB as you mentioned.

    But you should be able to easily circumvent that: you can have the URL as a String in a field and a getter/setter that convert from String to URL though. Then you map the field with the annotation.

    Or the opposite: the java.lang.URL in a field, and getter/setter to convert from URL to String, then you map the getter/setter with the annotation. I think it works as well.

提交回复
热议问题