javax.persistence.PersistenceException - JPA+Hibernate

后端 未结 3 900
北恋
北恋 2020-12-06 04:17

I am new to JPA, when I tried to run the following code, it showing error as \"cvc-elt.1: Cannot find the declaration of element \'persistence\'.\"

3条回答
  •  我在风中等你
    2020-12-06 04:28

    The issue is a mismatch between your and your hibernate library requirements. Copy and paste the whole persistence tag with name spaces (xmlns) from a reliable sample. Then check your library version, below.

    From hibernate.org: http://hibernate.org/orm/downloads/

    Supported JPA Versions

    JPA 1.0: ORM 3.2+
    JPA 2.0: ORM 3.5+
    JPA 2.1: ORM 4.3+
    

    Note that newer ORM releases are backwards compatible with older JPA versions (ex: ORM 4.3 with JPA 1.0). However, newer ORM releases may not be compatible with older JPA containers.

    The JPA version is the same as the persistence version. The ORM is the version of hibernate. So your persistence file has . So, as of now, you want only the hibernate library and version below (or a later version):

    WEB-INF/lib/hibernate-entitymanager-4.3.0.Final.jar
    

    or Maven pom.xml:

    
    
        org.hibernate
        hibernate-entitymanager
        4.3.0.Final
    
    

    I spent a whole bunch of hours on this one. I hope my time spent saves yours!

提交回复
热议问题