javascript - hibernate 启动报错hibernate.properties not found
PHPz
PHPz 2017-04-11 13:02:14
[JavaScript讨论组]

hibernate.cfg.xml




    
        root
        123
        com.mysql.jdbc.Driver
        jdbc:mysql:///localhost:3306/hibernate?useUnicode=true&characterEncoding=UTF-8
        org.hibernate.dialect.MySQLDialect
        
        true
        true
        create
        
        
    

Students.hbm.xml





    
        
            
            
        
        
            
        
        
            
        
        
            
        
        
            
        
    

Students.java

import java.util.Date;

//学生类
public class Students {
    private int sid;
    private String sname;
    private String gender;
    private Date birthday;
    private String address;
    
    public Students(){
        
    }
    
    public Students(int sid, String sname, String gender, Date birthday,
            String address) {
        this.sid = sid;
        this.sname = sname;
        this.gender = gender;
        this.birthday = birthday;
        this.address = address;
    }

    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String toString() {
        return "Students [sid=" + sid + ", sname=" + sname + ", gender="
                + gender + ", birthday=" + birthday + ", address=" + address
                + "]";
    }
    
    
}

StudentsTest.java

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class StudentsTest {
    
    private SessionFactory sessionFactory;
    private Session session;
    private Transaction transaction;
    
    @Before
    public void init(){

        Configuration configuration=new Configuration().configure();

        sessionFactory=configuration.buildSessionFactory();

        session= sessionFactory.openSession();

        transaction=session.beginTransaction();
    }
    
    @After
    public void destory(){
        transaction.commit();
        session.close();
        sessionFactory.close();
    }
    
    @Test
    public void testSaveStudents(){
        Students s = new Students(1,"张三丰","男",new Date(),"武当山");
        session.save(s);
    }
}

报错信息:
二月 16, 2017 1:14:19 上午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.7.Final}
二月 16, 2017 1:14:19 上午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
二月 16, 2017 1:14:19 上午 org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.... Use namespace http://www.hibernate.org/dtd/... instead. Support for obsolete DTD/XSD namespaces may be removed at any time.

提示找不到hibernate.properties 这个文件。。怎么回事?

PHPz
PHPz

学习是最好的投资!

全部回复(2)
ringa_lee

搞定了 首先参考这篇文章,http://blog.163.com/xh_ding/b...
因为Hibernate 4废弃buildSessionFactory,所以先按照我给的网页去修改,可能会报错,导入这两个包import org.hibernate.service.ServiceRegistryBuilder;

运行成功后如图


其实我5.10号就答辩了,现在才学hibernate,真是作死啊

阿神

不会啊...该方法可以用啊

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号