報錯了,求原因
我的test.java部分
public class Test {
public static void main(String[] args) {
add();
//findStudentsByGrade();
//update();
//delete();
}
//將學(xué)生添加到班級
public static void add(){
Grade g=new Grade("Java一班", "Java軟件開發(fā)一班");
Student stu1=new Student("張三", "男");
Student stu2=new Student("穆女神", "女");
//如果希望在學(xué)生表中添加對應(yīng)的班級編號,需要在班級中添加學(xué)生,建立關(guān)聯(lián)關(guān)系
/*g.getStudents().add(stu1);
g.getStudents().add(stu2);*/
Session session=HibernateUtil.getSession();
Transaction tx=session.beginTransaction();
session.save(g);
session.save(stu1);
session.save(stu2);
tx.commit();
HibernateUtil.closeSession(session);
}
}
2016-08-31
樓主錯誤解決了么?怎么解決的?
2016-03-23
配置文件代碼:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration>
? ? ? ?<!-- ? xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
? ? ? ? xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
? ? ? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">-->
? <session-factory>
? <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
? <property name="connection.driver_class">org.mysql.jdbc.Driver</property>
? ? <property name="connection.username">root</property>
? ? <property name="connection.password">030105</property>
? ? ? ? <property name="connection.url">
? ? ? ? <![CDATA[
? ? ? ? ?jdbc:mysql://localhost:3306/imooc?useUnicode=true&characterEncoding=utf8
? ? ? ? ]]>
? ? ? ? </property>
? ? ? ?<property name="show_sql">true</property>
? ? <property name="hbm2ddl.auto">update</property>
? ? <!-- 指定映射文件路徑 -->
<mapping resource="com/imooc/entity/Grade.hbm.xml"/>
<mapping resource="com/imooc/entity/Student.hbm.xml"/>
? </session-factory>
</hibernate-configuration>
2016-03-23
根據(jù)報錯信息是你的hibernate.cfg.xml文件有地方寫錯了