-1

I try:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
protected List<URL> urlList;

But I get error:

org.springframework.beans.factory.BeanCreationException: Error creating
 bean with name 'entityManagerFactory' defined in ServletContext resource
 [/WEB-INF/servlet-context.xml]: Invocation of init method failed; nested
 exception is org.hibernate.AnnotationException: Use of @OneToMany or
 @ManyToMany targeting an unmapped class:
 my.package.MyModel.urlList[java.net.URL]

I saw this answers, but I can't mapping list of URLs.

Community
  • 1
  • 1
mkczyk
  • 2,460
  • 2
  • 25
  • 40

2 Answers2

1

Using an ElementCollection and CollectionTable is the way to map a Collection of NON-ENTITY elements.

@ElementCollection
@CollectionTable(name="MY_URLS")
Collection<URL> urlList;

Then it would depend on whether your JPA provider supports persistence of that element type (URL) out of the box. My provider (DataNucleus) does. You always can use AttributeConverter if it doesn't

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
-1

What version of Hibernate are you using? Also, in your database, what is the datatype of the column; is it varchar, or something else?

From what I am understanding, it looks like your issue is that Hibernate does not know how to translate the column in the database to the java.net.URL class, a Hibernate type would need to be defined to tell Hibernate how to handle this conversion.

It looks like Hibernate does have a built-in type that should handle this conversion, assuming you are using a version of Hibernate that has it -- 3.6 or greater, I think.

Try adding this annotation to your List:

@Type(type="org.hibernate.type.UrlType")

If your version of Hibernate does not have org.hibernate.type.UrlType or if your database column data type is not a varchar, you will need to create a custom Hibernate type that defines what Hibernate needs to do to convert whatever data type in the database to a java.net.URL and back. Let us know if it gets to that point and we can give you more information.

Chatoyancy
  • 143
  • 1
  • 17