zod
zod

Reputation: 2798

Hibernate, (netbeans 7.1.2, maven) unable to use ElementCollection attribute

A my SQL database has an "Item" table. Each "item" can have many alternate labels. These are stored in another table called "ItemAltLabel". The foreign key is “ItemID”.

I am trying to represent this in java as an entity which has a set of string alternate labels.

My property looks like this:

@ElementCollection
@CollectionTable(name="ItemAltLabel", joinColumns=@JoinColumn(name="ItemID"))
@Column(name="Label")
private Set<String> alternateLabels;

Should this be correct?

The error I get is:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityBroker': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.hibernate.SessionFactory com.porism.dao.BaseBroker.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(Label)]

I found this post, which suggests it is a bug in the version of hibernate I am using:

http://blog.m1key.me/2010/06/orghibernatemappingexception-could-not.html

“If you are getting this error in a similar situation, the reason is a bug in your Hibernate implementation and you should get a newer one (I recommend 3.5.3-Final or later).”

My pom file refers to 3 hibernate dependencies:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate</artifactId>
  <version>3.2.5.ga</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>3.3.2.GA</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>3.3.2.GA</version>
</dependency>

I have tried updating these to 3.5.3-Final (as the post suggests).

My repositories look like this:

http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo eclipselink default Repository for library Library[eclipselink] http://download.java.net/maven/2/ hibernate-support default Repository for library Library[hibernate-support]

The error I get when trying to build the project is:

Failed to execute goal on project InformWebServices: Could not resolve dependencies for project porism:InformWebServices:war:1.0: Could not transfer artifact org.hibernate:hibernate:jar:3.5.3-Final from/to eclipselink (http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo): Connection to http://ftp.ing.umu.se refused: Connection timed out: connect -> [Help 1]

If I remove the dependency on hibernate 3.5.3-Final, the other two dependencies are downloaded successfully. The project builds; but a new error appears:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityBroker': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.hibernate.SessionFactory com.porism.dao.BaseBroker.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/springmvc-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.AnnotationConfiguration

I am using NetBeans 7.1.2 and maven.

As you can probably tell, I have been handed a project, and don’t have a clue what I am doing. Any help would be greatly appreciated.

I have tried upgrading to hibernate 4, but this resulted in a host of problems, and I would prefer to remain as close to the version I was using as possible.

Upvotes: 0

Views: 1250

Answers (1)

Steve Ebersole
Steve Ebersole

Reputation: 9443

Not sure what the org.hibernate:hibernate dependency is supposed to refer to. But that is certainly not a jar we (the Hibernate team) produce.

You should be fine specifying just the org.hibernate:hibernate-entitymanager dependency. It will actually pull in org.hibernate:hibernate-core transitively. And these are the ones that should be upgraded to 3.5+

Upvotes: 1

Related Questions