Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.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 未映射Enity[从类型o中选择o]_Java_Hibernate - Fatal编程技术网

Java 未映射Enity[从类型o中选择o]

Java 未映射Enity[从类型o中选择o],java,hibernate,Java,Hibernate,我试图用hibernate创建一个小项目,但我得到了错误“类型未映射[select o from Type o]”,我在hibernate.cfg.xml中添加了映射,但仍然有错误 Type.java: package com.formation.gestionprojet.doa.entity; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; import

我试图用hibernate创建一个小项目,但我得到了错误“类型未映射[select o from Type o]”,我在hibernate.cfg.xml中添加了映射,但仍然有错误

Type.java:

package com.formation.gestionprojet.doa.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name="Type")
public class Type implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = 1L;

@Id
private Long id;

private String name;

private String description;

private String active;




public Type() {
    super();
    // TODO Auto-generated constructor stub
}

public Long getId() {
    return id;
}

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

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String getActive() {
    return active;
}

public void setActive(String active) {
    this.active = active;
}   

}
hibernate.org.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>


<session-factory>

<!--  database connection setting -->

<property name ="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/gestion_projet?createDatabaseIfNotExist=true</property>
<property name="connection.username">root</property>
<property name= "connection.password">root</property>

<!-- Dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Disable the second level cache -->

<property name="cache.provider_class" >org.hibernate.cache.NoCacheProvider</property>

<!-- echo all executed SQL to stdout -->

<property name="show_sql">true</property>

<!-- Drope and re-create the database -->
<property name="hbm2ddl.auto">update</property>

<!-- mapping -->


<mapping class= "com.formation.gestionprojet.doa.entity.Type"/>


</session-factory>

</hibernate-configuration>
Test.Java

package com.formation.gestionprojet.utils;

import org.hibernate.Session;



public class Test {

    static Session session = HibernateUtil.openSession();

    public static void main(String[] args) {

        session.createQuery("select o from Type o").list();



    }

}

解决了!问题是我使用的hibernate版本,所以我对它进行了更改,在HibernateUtil中进行了更改。

Type
是MySQL中的保留字。请尝试为您的实体和表使用不同的名称。谢谢您的回答,仍然是相同的错误。请提供任何建议!解决了的!问题是我使用的hibernate版本,所以我对它进行了更改,对HibernateUtil进行了更改。
package com.formation.gestionprojet.utils;

import org.hibernate.Session;



public class Test {

    static Session session = HibernateUtil.openSession();

    public static void main(String[] args) {

        session.createQuery("select o from Type o").list();



    }

}