-1

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="JPAWithEntityManager" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>com.Student</class>
    <properties>
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpa"/>
    <property name="javax.persistence.jdbc.user" value="root"/>
    <property name="javax.persistence.jdbc.password" value="root"/>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.format_sql" value="true"/>
    <property name="hibernate.dialect" value="org.hibernate.MySQL5InnoDBDialect"/>
    <property name="hibernate.hbm.2ddl.auto" value="create"/>
    </properties>
    </persistence-unit>
</persistence>

Why is it showing "Cannot find the declaration of element 'persistence'" .

kjhughes
  • 106,133
  • 27
  • 181
  • 240
P Yoga Prudhvi
  • 107
  • 2
  • 3
  • 11

4 Answers4

0

Your XML is valid against the XSD given by its xsi:schemaLocation.

If connectivity to the remote site hosting the XSD was/is an issue, as a quick check, copy the XSD locally and update xsi:schemaLocation to the local location. In the long run, consider using an XML catalog in order to resolve the reference to a reliable local location.

See also:

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I'd not got what you are trying to stay, can you explain briefly, I had started JPA from today itself, so I'm new to this.I had changed the version to 2.0 from 2.1, but it still not seems to work. – P Yoga Prudhvi May 13 '20 at 16:08
  • If this answer does not help, and you're unable to ask a specific follow-up to clarify what's unclear to you, I won't be able to help further. – kjhughes May 13 '20 at 16:41
  • The above program is running by adding these 2 properties, can anyone tell me the reason ` ` – P Yoga Prudhvi May 13 '20 at 17:16
0
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="JPA" transaction-type="RESOURCE_LOCAL"> 
    <class>com.Student</class>
     <properties>
         <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpa"/>
         <property name="javax.persistence.jdbc.user" value="root"/>
         <property name="javax.persistence.jdbc.password" value="root"/>
         <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.dialect" value="org.hibernate.MySQL5InnoDBDialect" />
            <property name="hibernate.hbm.2ddl.auto" value="create" />
         <property name="eclipselink.logging.level" value="FINE"/>
         <property name="eclipselink.ddl-generation" value="create-tables"/>
      </properties>
    </persistence-unit>
</persistence>
P Yoga Prudhvi
  • 107
  • 2
  • 3
  • 11
0

You may be missing a hibernate dependency. Try adding

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.4.15.Final</version>
</dependency>
Dezmond H
  • 25
  • 7
0

I had made new project but this time I'd selected another option, i.e "Dicover Annotated Class Automatically", by selecting this tab my program is running.

P Yoga Prudhvi
  • 107
  • 2
  • 3
  • 11