2012-05-16 27 views
0

我的SQL数据库有一个“Item”表。每个“项目”可以有许多替代标签。这些存储在另一个名为“ItemAltLabel”的表中。外键是“ItemID”。Hibernate,(netbeans 7.1.2,maven)无法使用ElementCollection属性

我想在java中将其表示为具有一组字符串替代标签的实体。

我的财产是这样的:

@ElementCollection 
@CollectionTable(name="ItemAltLabel", [email protected](name="ItemID")) 
@Column(name="Label") 
private Set<String> alternateLabels; 

如果这是正确的吗?

我得到的错误是:

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)]

我发现这个职位,这表明它处于休眠的版本中的错误,我使用:

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

“如果你是在类似的情况下得到这个错误,原因是你的Hibernate实现中存在一个错误,你应该得到一个更新的错误(我推荐3.5.3-最终或更高版本)。“

我的POM文件是指3只Hibernate依赖:

<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> 

我试图更新这些3.5.3决赛(视后建议)。

我的资料库是这样的:

http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo 的EclipseLink 默认 存储库库库[的EclipseLink ] http://download.java.net/maven/2/ 休眠支持 默认 存储库库库[休眠支持]

试图建立项目时,我得到的错误是:

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]

如果我删除有关休眠3.5.3决赛的依赖,另外两个依赖被成功下载。项目建立;但出现新错误:

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

我使用的是NetBeans 7.1.2和maven。

正如你可能知道的那样,我已经递交了一个项目,并且不知道我在做什么。任何帮助将不胜感激。

我已经尝试升级到休眠4,但这导致了一系列问题,我宁愿保持尽可能接近我使用的版本。

回答

1

不确定org.hibernate:hibernate依赖关系应该引用什么。但这绝对不是我们(Hibernate团队)产生的瓶子。

你应该很好的指定org.hibernate:hibernate-entitymanager依赖。它实际上会传入org.hibernate:hibernate-core。这些都是应该升级到3.5 +

+0

感谢您的帮助。我发现org.hibernate:hibernate是一个pom文件,需要一个 pom。我还必须添加一个依赖到org.slf4j:slf4j-log4j12(1.5.0) – zod