簡體   English   中英

為什么Hibernate拋出異常“java.lang.NoSuchMethodError:javax.persistence.UniqueConstraint.name()”?

[英]Why does Hibernate throw exception “java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name()”?

為什么以下Hibernate映射聲明中的UniqueConstraint注釋會導致異常java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name() (請參閱下面的堆棧跟蹤)? 請注意,當我刪除UniqueConstraint注釋時,Hibernate不會拋出異常,Spring會成功創建應用程序上下文。

源代碼:

@Entity
@Table(name="TB_USER_ACCESS"
    ,schema="ABSOL_USER"
    , uniqueConstraints = @UniqueConstraint(columnNames={"USER_ID", "BUSINESS_GROUP_ID", "BUSINESS_FUNCTION_ID"}) 
)
public class UserAccess  implements java.io.Serializable {
...

異常堆棧跟蹤:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name()Ljava/lang/String;
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.db.abstrack.util.SpringContextFactory.<init>(SpringContextFactory.java:18)
    at com.db.abstrack.util.SpringContextFactory.<clinit>(SpringContextFactory.java:13)
    ... 60 more
Caused by: java.lang.NoSuchMethodError: javax.persistence.UniqueConstraint.name()Ljava/lang/String;
    at org.hibernate.cfg.annotations.TableBinder.buildUniqueConstraintHolders(TableBinder.java:544)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:550)
    at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:636)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:359)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    ... 73 more

軟件配置:

  • Hibernate 3.5.5-決賽
  • Spring 3.0.4.RELEASE
  • WebLogic Server 10.3.2

pom.xml相關Maven 2依賴項:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.5.5-Final</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>3.0.4.RELEASE</version>
    <scope>compile</scope>
</dependency>

Hibernate依賴項:

[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.5-Final:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:3.5.5-Final:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |  \- javax.transaction:jta:jar:1.1:compile
[INFO] |  +- org.hibernate:hibernate-annotations:jar:3.5.5-Final:compile
[INFO] |  |  \- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] |  +- cglib:cglib:jar:2.2:compile
[INFO] |  |  \- asm:asm:jar:3.1:compile
[INFO] |  \- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile

Spring依賴項:

[INFO] +- org.springframework:spring-orm:jar:3.0.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.0.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:3.0.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-asm:jar:3.0.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:3.0.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:3.0.4.RELEASE:compile
[INFO] |     +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |     +- org.springframework:spring-aop:jar:3.0.4.RELEASE:compile
[INFO] |     \- org.springframework:spring-context:jar:3.0.4.RELEASE:compile
[INFO] |        \- org.springframework:spring-expression:jar:3.0.4.RELEASE:compile
[INFO] +- net.sf.ehcache:ehcache-core:jar:2.2.0:compile

UniqueConstraint.name()出現在JPA 2中。由於您具有正確的JPA依賴關系,我假設您的WebLogic已經發布了JPA 1.0,它會覆蓋您的jar。 我想,你可以在你做到這一點weblogic-application.xml (如注意這里 ):

<prefer-application-packages>
  <package-name>javax.persistence.*</package-name>
</prefer-application-packages>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM