Search code examples
javahibernate

Hibernate - How to store java.net.URL into a database through Hibernate


I have a field URL countryURL; in a Country class. I want to store its data into a COUNTRY table in a database through Hibernate.

Which Hibernate type I should use in the hibernate mapping file

<property column="COUNTRY_URL" name="countryURL" type="..."/>

It is not excepting string and text type.


Solution

  • You can create a org.hibernate.UserType for URL which maps to a varchar column. See Custom value types in the reference documentation.