有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我不知道为什么我的非常简单的JPA项目不能工作

我有组织。postgresql。util。错误:关系“角色”不存在,我不知道为什么

实体类

package com.example.SpringBootTest1.model;

import lombok.*;
import javax.persistence.*;

@ToString
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "roles")
public class Role
{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Setter
    @Getter
    private int id;
    
    @Setter
    @Getter
    @Column(name = "name")
    private String name;
}

main()

public static void main(String[] args)
{
        
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("role_pu");
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();
        
    Role role1 = new Role();
    role1.setName("role111");
    entityManager.persist(role1);
    entityManager.getTransaction().commit();
    entityManagerFactory.close();
    entityManager.close();
}

资源/META-INF/持久性。xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="role_pu" transaction-type="RESOURCE_LOCAL">

        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <class>com.example.SpringBootTest1.model.Role</class>

        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/postgres"/>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
            <property name="javax.persistence.jdbc.user" value="postgres"/>
            <property name="javax.persistence.jdbc.password" value="123"/>

            <property name="dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/>
            <property name="show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hdm2ddl.auto" value="create"/>
        </properties>

    </persistence-unit>
</persistence>

pom.xml我有
hibernate-core
postgresql
lombok
为什么我会有这样的错误,为什么会这样?我读过this question,它对我没有帮助


共 (1) 个答案