JPA property java.net.URL

后端 未结 2 1141
无人及你
无人及你 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条回答
  •  臣服心动
    2020-12-16 17:37

    You can also use JPA AttributeConverter such as explain here to map a URL object into a String column (Hibernate does that out of the box)

    Or, if you are only interrested in validation, you may use BeanValidation. There is a @URL annotation in HibernateValidator extension you can also create your own constraint such as explain here

    I personnaly prefer the BeanValidation solution because considering url as java.net.URL bring some complexity : need for JPA AttributeConverter, JSF Converter, JAXB Adapter... while it is just for validation

提交回复
热议问题