Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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 org.hibernate.MappingException:未知实体:me.News_Java_Xml - Fatal编程技术网

Java org.hibernate.MappingException:未知实体:me.News

Java org.hibernate.MappingException:未知实体:me.News,java,xml,Java,Xml,好的,这个问题与同一标题的问题不同,我尝试了很多解决方案,但我解决不了 实体: package me; import javax.persistence.*; @Entity @Table(name = "news_inf") public class News { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String title;

好的,这个问题与同一标题的问题不同,我尝试了很多解决方案,但我解决不了

实体:

package me;

import javax.persistence.*;

@Entity
@Table(name = "news_inf")
public class News {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String title;
    private String content;

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

    public Integer getId() {
        return this.id;
    }

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

    public String getTitle() {
        return this.title;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getContent() {
        return this.content;
    }
}
测试呢

package me;

import org.hibernate.*;
import org.hibernate.cfg.*;
import org.hibernate.service.*;
import org.hibernate.boot.registry.*;

public class Test3 {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration().configure();
        ServiceRegistry serviceRegistry = new  StandardServiceRegistryBuilder()
            .applySettings(conf.getProperties())
            .build();
        SessionFactory sf = conf.buildSessionFactory(serviceRegistry);
        Session sess = sf.openSession();
        Transaction tx = sess.beginTransaction();
        News n = new News();
        n.setTitle("1234");
        n.setContent("1234");
        sess.save(n);
        tx.commit();
        sess.close();
        sf.close();
    }
}
hibernate.cfg.xml文件

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url"> <![CDATA[jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf8]]></property>
        <property name="connection.username">root</property>
        <property name="connection.password">1234</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.min_size">1</property>
        <property name="hibernate.c3p0.timeout">5000</property>
        <property name="hibernate.c3p0.max_statements">100</property>
        <property name="hibernate.c3p0.idle_test_period">3000</property>
        <property name="hibernate.c3p0.acquire_increment">2</property>
        <property name="hibernate.c3p0.validate">true</property>
        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="hbm2ddl.auto">create</property><!--①-->
        <property name="show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
        <mapping class="me.News"/>
    </session-factory>
</hibernate-configuration>

com.mysql.jdbc.Driver
根
1234
20
1.
5000
100
3000
2.
真的
org.hibernate.dialogue.mysql5innodbdialogue
创造
真的
真的

我不知道为什么我错了?我需要帮助,谢谢

也许还要添加xml您确定您的测试正在使用xml吗?是的,控制台显示了名称和密码的消息