为什么创建不了SessionFactory?
Student.java
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Student {
private int id;
private String name;
private int age;
@Id
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
hibernate.cfg.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 settings -->
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=db_hibernate
</property>
<property name="connection.username">sa</property>
<property name="connection.password">sa</property>
<!-- JDBC connection pool (use the built-in) 连接池-->
<!-- <property name="connection.pool_size">1</property> -->
<!-- SQL dialect 方言 -->
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">create</property> -->
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="myeclipse.connection.profile">
sqlserver2000
</property>
<mapping class="com.newer.model.Student" />
</session-factory>
</hibernate-configuration>
StudentTest.java
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
public class StudentTest {
public static void main(String[] args) {
Student s = new Student();
s.setName("s1");
s.setAge(1);
Configuration con = new AnnotationConfiguration();
System.out.println(con);
con.configure();
SessionFactory sf = con.buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();
}
}
运行上面的代码报错如下, 请大侠们帮忙解决下
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.cfg.AnnotationConfiguration@121f1d
Exception in t