tags:

views:

182

answers:

3

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.

+3  A: 

You could write your own user type, but it might be easier to perform the conversion String<->Url in property getters and setters:

private void setRawUrl(String s) {
    this.url = new Url(s);
}

private String getRawUrl() {
    return url.toString();
}

and map the property rawUrl with type string.

meriton
+4  A: 

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

Lachlan Roche
A: 

I'd store it as String. No need to make your life harder by implementing a custom type. That is, change URL to Stringin Country.

Bozho
You mean that I should change the datatype of `countryURL` field in the `Country` class from `URL` to `String`
Yatendra Goel
or you want to say what @meriton had mentioned?
Yatendra Goel
yes, change from `URL` to `String`
Bozho