Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring boot JPA中的持久性和休眠错误_Java_Spring_Hibernate_Jpa - Fatal编程技术网

Java spring boot JPA中的持久性和休眠错误

Java spring boot JPA中的持久性和休眠错误,java,spring,hibernate,jpa,Java,Spring,Hibernate,Jpa,我有这个错误,当我转到jpa控制台并运行命令时,我得到以下结果: persistenceUnit/Hibernate Connection to persistenceUnit/Hibernate failed Could not create connection to database server. Attempted reconnect 3 times 尽管如此,我可以在intellij的数据库选项卡中看到我的数据库。它还创建了entityclass

我有这个错误,当我转到jpa控制台并运行命令时,我得到以下结果:

persistenceUnit/Hibernate
         Connection to persistenceUnit/Hibernate failed
         Could not create connection to database server. Attempted reconnect 3 times
尽管如此,我可以在intellij的数据库选项卡中看到我的数据库。它还创建了entityclass

那么,为什么我会有这些错误呢

它没有创建persistence.xml,所以我创建了它并将其放入src/web-inf

我的实体

ava.lang.RuntimeException: org.hibernate.AnnotationException: No identifier specified for entity: com.models.MovieEntity
     at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)
     at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)
     at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)
     at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
     at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
     at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
实体类给出了无目录的错误。

  • 连接字符串中似乎缺少数据库
  • 很可能您的实体没有用@Id注释的字段
您的实际错误是:

@Entity
@Table(name = "movie", schema = "mysql", catalog = "")
public class MovieEntity {
    private int id;
    private String title;
    private String actors;

    @Basic
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Id
    @Column(name = "Title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Basic
    @Column(name = "Actors")
    public String getActors() {
        return actors;
    }

    public void setActors(String actors) {
        this.actors = actors;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MovieEntity that = (MovieEntity) o;

        if (id != that.id) return false;
        if (title != null ? !title.equals(that.title) : that.title != null) return false;
        if (actors != null ? !actors.equals(that.actors) : that.actors != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (actors != null ? actors.hashCode() : 0);
        return result;
    }
}
必须在
com.models.MovieEntity
类中指定id

No identifier specified for entity: com.models.MovieEntity

看到您的配置我可以看到您的用户名和密码为空,现在可能您发布的persistence.xml就是一个示例。您的一个错误
对用户'root'@'localhost'的访问被拒绝(使用密码:YES)
请按照我的建议检查您的数据库是否配置了密码并使用它(在linux上没有配置的标准安装中,我并不疯狂,很多时候我的密码都是空的)。然后,我可以看到您在标题属性上有@Id,而您的sql for tabel生成可能要求Id是主键


我希望这能帮助你

I pıut我的实体,但有@id。不是吗?private int id;我有这个。我把我的代码放进去了。你能看一下吗?我需要一个教程来遵循,因为我使用intellj。我不能让它工作。例如,我将hibernate配置文件添加到资源中,然后metainf资源中的jpa文件消失。当我添加它时,hibernate dis出现。我无法使其工作。我使用jpa控制台和其他控制台,但两者都不工作。在我的持久性文件中有很多用户名密码,我不使用所有用户名密码。你可以从我的开源项目链接获取灵感:。在这个项目中,我使用Spring数据,但基本上使用Spring引导,你可以使用应用程序,属性用于put hear configuration in practis您可以在application.properties/application.yml中配置所有数据源配置,并删除your persistence.xml,但我看不到。例如,在开始时,我选择spring Initializer创建pom文件,是否很好?然后从模块中添加jpa和hibernate。
@Entity
@Table(name = "movie", schema = "mysql", catalog = "")
public class MovieEntity {
    private int id;
    private String title;
    private String actors;

    @Basic
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Id
    @Column(name = "Title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Basic
    @Column(name = "Actors")
    public String getActors() {
        return actors;
    }

    public void setActors(String actors) {
        this.actors = actors;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MovieEntity that = (MovieEntity) o;

        if (id != that.id) return false;
        if (title != null ? !title.equals(that.title) : that.title != null) return false;
        if (actors != null ? !actors.equals(that.actors) : that.actors != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (actors != null ? actors.hashCode() : 0);
        return result;
    }
}
No identifier specified for entity: com.models.MovieEntity
@javax.persistence.Id
private Long id;