解决方案 »
- 运行某个命令,提示权限不够。(linux系统下)
- JSP的页面里面有JS的代码怎么调试?
- struts.locale=en_GB 是什么东西 struts里面的!
- jbuilder创建webservices找不到WebModule问题!
- 谁能给我一个jsp调用ejb的helloworld例子?
- JAVA如何调EXE
- CMP设计EJB时主键自动增长的问题
- 用jdbc for sqlserver 2000(Microsoft的)调用存储过程为何返回不了记录集
- 如何在JBuilder7中连接远程MS SQL2k数据库?
- js 闭包。。。闭包。。。。 大问题。。。!!!
- JAVA使用POI读取EXCEL错误
- spring+hibernate注解方式的问题
private int id;
private String sname;
private int age;
public int getAge() {
return age;
}
public int getId() {
return id;
}
public String getSname() {
return sname;
}
public void setAge(int age) {
this.age = age;
}
public void setId(int id) {
this.id = id;
}
public void setSname(String sname) {
this.sname = sname;
}
}
import org.hibernate.cfg.*;
import org.hibernate.Session;
import com.lv.hibernate.model.Student;
public class StudentTest {
public static void main(String[] args) {
Student s = new Student();
s.setId(1);
s.setSname("s1");
s.setAge(1);
Configuration cfg = new Configuration();
SessionFactory sf = cfg.configure().buildSessionFactory();
//SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();
}
}
<!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> <!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">sa</property>
<property name="connection.password">lvailing</property> <!-- JDBC connection pool (use the built-in) -->
<!-- <property name="connection.pool_size">1</property> --> <!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</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> <!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">update</property> -->
<mapping resource="com/lv/hibernate/model/Student.hbm.xml"/> </session-factory></hibernate-configuration
>
<class name="student">
<id name="id"></id>
<property name="sname"></property>
<property name="age"></property>
</class>
</hibernate-mapping>改成大写的
com/lv/hibernate/model/student (wrong name: com/lv/hibernate/model/Student
看来楼主要多学学英文了啊、Student.hbm.xml他找不到这个类
<class name="student">
类名都是开头大写的、上面都已经回答的很仔细了。
程序员得仔细些心细