在学习jpa注解
在实体类上报这个错,但是运行起来却没有错
Class "org.lw.jpa.entity.Person" is mapped, but is not included in any persistence unit
这是什么原因呢?是编译器还是什么呢?

解决方案 »

  1.   

    在resources的persistence.xml文件中
    类似于;<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="visitorPU" transaction-type="RESOURCE_LOCAL">
    <class>com.cybersoft4u.example.domain.Visitor</class>
    <class>com.cybersoft4u.example.domain.Comment</class>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
    <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->
    </properties>
    </persistence-unit>
    </persistence>
      

  2.   

    嗯,谢谢,我刚开始注意了这个问题,但是我是这样的,它报错:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
        
    <persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">

       <properties>
    <property name = "hibernate.connection.driver_class" value = "com.mysql.jdbc.Driver"/>
    <property name = "hibernate.connection.url" value = "jdbc:mysql://localhost:3306/jpa"/>
    <property name = "hibernate.connection.username" value = "root"/>
    <property name = "hibernate.connection.password" value = "root"/>
    <property name="hibernate.connection.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
       </properties>
       <class>org.lw.jpa.entity.Person</class>
    </persistence-unit>
      
    </persistence>
    看来class只能放在properties的上面呀,是这样的吗?
      

  3.   


    其实,<properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
                <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop"/> -->
            </properties>这段,不要放在这个文件里面。因为一般dataSource都在别的地方配置,最好是一个独立的xml中。
      

  4.   


    嗯,放在spring配置文件中也可以。