2 weixin 37277866 weixin_37277866 于 2017.01.07 14:20 提问

请大家帮帮忙,hibernate 的wt

月 07, 2017 2:12:18 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.6.Final}
一月 07, 2017 2:12:18 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:53)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at com.lyq.hibernatetest.HibernateTest.main(HibernateTest.java:13)

我的配置如下
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">



org.hibernate.dialect.MySQLInnoDBDialect
com.mysql.jdbc.Driver
jdbc:mysql:///test
root
946473667
update
true
true


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">










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

import com.lyq.test.Person;

public class HibernateTest {

public static void main(String[] args) {
    Configuration cfg = new Configuration().configure();
    SessionFactory factory = cfg.buildSessionFactory();
    Session session = factory.openSession();
    Transaction tx = session.beginTransaction();


    Person p = new Person("amdit",123456,new java.util.Date());

    session.save(p);
    tx.commit();
    session.close();
    factory.close();
}

}

public class Person {
private Integer id;
private String name;
private Integer age;
private Date birthday;

/**
 * 
 */
public Person() {

}

@Override
public String toString() {
    return "Person [id=" + id + ", name=" + name + ", age=" + age + ", birthday=" + birthday + "]";
}

/**
 * @param id
 * @param name
 * @param age
 * @param birthday
 */
public Person( String name, Integer age, Date birthday) {

    this.name = name;
    this.age = age;
    this.birthday = birthday;
}

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

public Integer getAge() {
    return age;
}
public void setAge(Integer age) {
    this.age = age;
}


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

}

1个回答

JE_GE
JE_GE   2017.01.09 12:18
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!