亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

報錯了,求原因

http://img1.sycdn.imooc.com//56f0f87200012fbc08850445.jpg

我的test.java部分

public class Test {

public static void main(String[] args) {

add();

//findStudentsByGrade();

//update();

//delete();

}

//將學生添加到班級

public static void add(){

Grade g=new Grade("Java一班", "Java軟件開發一班");

Student stu1=new Student("張三", "男");

Student stu2=new Student("穆女神", "女");

//如果希望在學生表中添加對應的班級編號,需要在班級中添加學生,建立關聯關系

/*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);

}

}


正在回答

3 回答

樓主錯誤解決了么?怎么解決的?

0 回復 有任何疑惑可以回復我~

配置文件代碼:

<?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>


0 回復 有任何疑惑可以回復我~

根據報錯信息是你的hibernate.cfg.xml文件有地方寫錯了


0 回復 有任何疑惑可以回復我~
#1

黑豆0 提問者

配置文件代碼在下面
2016-03-23 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Hibernate初探之一對多映射
  • 參與學習       42159    人
  • 解答問題       310    個

Hibernate中一對多關聯映射配置,以及cascade和inverse屬性作用

進入課程

報錯了,求原因

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號