Class “model.Address” is listed in the persistence.xml file but not mapped

后端 未结 9 1109
梦如初夏
梦如初夏 2020-12-24 11:59

I have created a JPA project. In that Eclipse displays the following error on the entity class.

Class \"model.Address\" is listed in the

相关标签:
9条回答
  • 2020-12-24 12:25

    Right click on jpa project

    then

    enter image description here

    0 讨论(0)
  • 2020-12-24 12:25

    You need to create a persistence file and a ORM mapping file for JPA, refer the mapping file from persistence file.

    <persistence-unit name="persistenceUnit"
        transaction-type="RESOURCE_LOCAL">
        <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
        <mapping-file>META-INF/hbase-orm.xml</mapping-file>
        <class>com.xxx.logcollector.entity.DefaultLogableEntity</class>
        <properties>
            <property name="datanucleus.jpa.addClassTransformer" value="false" />
            <property name="datanucleus.managedRuntime" value="false" />
    

    ....

    Create ORM mapping file

    <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
        version="1.0">
        <entity class="com.xxx.cne.logcollector.entity.DefaultLogableEntity"
            name="DefaultLogableEntity">
            <table name="RAW_LOG_COLLECTION" />
            <attributes>
                <id name="clientHostIP">
                    <column name="ANALYTICS:CLIENT_IP" />
                </id>
                <basic name="requestDateTime">
                    <column name="ANALYTICS:REQUEST_DATETIME" />
                </basic>
    

    ...

    Create entity manager in spring

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="persistenceUnit"></property>
    

    0 讨论(0)
  • 2020-12-24 12:26

    This is an Eclipse quirk. I recently had exactly this problem when I created a new JPA project with the JPA library configuration disabled, but didn't manually configure the JPA libraries before I created the entities by the Eclipse New JPA Entity wizard. After creating the entities I configured the JPA libraries in project's Build Path (just by adding target Java EE server runtime in Libraries), but the validation error still remains. I could solve it in at least one of following ways:

    1. Rightclick persistence.xml file, JPA Tools -> Synchronize Class List.
    2. Or, rightclick project, Validate.
    3. Or, close/reopen project.

    This is consistently reproducible. I was using Eclipse Indigo SR1. When I create the entities after configuring the JPA libraries, this validation error doesn't occur.

    0 讨论(0)
  • 2020-12-24 12:34

    It should be written like:

    @Entity
    **@Table(name="Address",schema="ABCD")** `
    

    ...or it could be written like :

    @Entity
    public class Address {
    
    } 
    
    0 讨论(0)
  • 2020-12-24 12:36

    Make sure your class is annotated with @Entity (from javax.persistence.Entity)

    I realise that's not the OP's problem, but I got caught by that and Google sent me here.

    0 讨论(0)
  • 2020-12-24 12:39

    Any of the above didnt work.

    For anyone who is searching for the "Class xxxx is mapped, but is not included in any persistence unit" error in Eclipse or RAD:

    1. Right-click on the project and choose properties.
    2. Select JPA
    3. Select the radio button "Discover annotated classes automatically"
    4. OK and wait for the project to finish building.

    These steps worked for me.

    0 讨论(0)
提交回复
热议问题