gpt4 book ai didi

java - 对象 [id=XYZ] 不是已知的实体类型

转载 作者:行者123 更新时间:2023-12-02 00:58:56 25 4
gpt4 key购买 nike

我创建了一个启用了 JPA 方面的新动态 Web 项目。我的项目仅包含 persistance.xml 文件、一个带注释的实体和持久性代码。

当我尝试执行持久性代码时,出现以下错误:对象:不是已知的实体类型。

我正在运行 Eclipse 4.12.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="ezimax" transaction-type="RESOURCE_LOCAL">
<class>za.co.ezimax.entity.Profile</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/ezimax_backend"/>
<property name="javax.persistence.jdbc.user" value="postgres"/>
<property name="javax.persistence.jdbc.password" value="xxxxxxx"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>

实体

package za.co.ezimax.entity;

import java.time.LocalDate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity()
@Table(name = "profile")
public class Profile {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

@Column(name="first_name", nullable = false, length = 80)
private String firstName;

@Column(name="last_name", nullable = false, length = 80)
private String lastName;

@Column(name="birth_date", nullable = false)
private LocalDate birthDate;

@Column(name="sex", nullable = false)
private int sex;

@Column(name="sex", nullable = false)
private String mobileMac;

@Column(name="sex", nullable = false, length = 12)
private String mobileNo;

@Column(name="birth_date", nullable = false)
private LocalDate registrationDate;

@Column(name="user_password", nullable = false, length = 80)
private char[] userPassword;

public Profile() {
}
}

持久性代码

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ezimax");
EntityManager em = emf.createEntityManager();

em.getTransaction().begin();

Profile profile = new Profile();
profile.setFirstName("Hendre");
profile.setLastName("Louw");
profile.setSex(1);
profile.setMobileMac("ff:ff:ff:ff:ff:ff:ff:ff");
profile.setMobileNo("+27830000000");
profile.setRegistrationDate(LocalDate.now());
profile.setUserPassword("password".toCharArray());

em.persist(profile);
em.getTransaction().commit();

em.close();
emf.close();

MAVEN

        <dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.1</version>
</dependency>

最佳答案

我升级到 org.eclipse.persistence.jpa 2.7.4,问题已解决。

关于java - 对象 [id=XYZ] 不是已知的实体类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57785700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com