Hibernate:persistence.xmlのエラー-要素 'persistence-unit'にテキストコンテンツを含めることはできません。コンテンツタイプは要素のみとして定義されています

Neethu S

私はHibernateを使用していますが、以下のpersistence.xmlは正常に機能していました。しかし、Eclipseのテーブルから新しいJPAエンティティを作成した後、persistence.xmlでエラーが発生します-要素 'persistence-unit'にテキストコンテンツを含めることはできません。コンテンツタイプは要素のみとして定義されています。新しいクラスをpersistence.xmlから削除しましたが、それでもエラーは解決しません。

<persistence version="2.2"
    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_2.xsd">
    <persistence-unit name="FirstJPAProject">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>com.boi.network.test.entity.Location</class>
        <class>com.boi.network.test.entity.Supportvendor</class>
        <class>com.boi.network.test.entity.Project</class>
        <properties>
            <!-- The JDBC URL to the database instance -->
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/boi?useSSL=false&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC"></property>          
            <property name="javax.persistence.jdbc.user" value="dba"></property>
            <property name="javax.persistence.jdbc.password" value="12345"></property>
        </properties>
    </persistence-unit>
</persistence>```
アマンくまゆ

Hibernateは自動検出をサポートしているため、クラス要素を削除してこのプロパティを追加するだけです。また、@ Entityアノテーションでクラスにアノテーションを付けます。

<persistence version="2.2"
    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_2.xsd">
    <persistence-unit name="FirstJPAProject">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <!--<class>com.boi.network.test.entity.Location</class>
        <class>com.boi.network.test.entity.Supportvendor</class>
        <class>com.boi.network.test.entity.Project</class>-->
        <properties>
            <!-- The JDBC URL to the database instance -->
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/boi?useSSL=false&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC"></property>          
            <property name="javax.persistence.jdbc.user" value="dba"></property>
            <property name="javax.persistence.jdbc.password" value="12345"></property>
            <property name="hibernate.archive.autodetection" value="class, hbm"/>
        </properties>
    </persistence-unit>
</persistence>```

この答えを見てください

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ