请教一个关于struts2中更新外键值的问题
我的一个表叫score,里面的属性为course_no(这个是外键,我的course表中的一个项),student_no(这个也是外键,我的student表中的一个项)。我现在想往这个score表中插入数据:
Course course = new Course();
course = courseService.findByCourseNo(courseNo);
Student student = new Student();
student = studentService.findByStudentId(studentId).get(0);
score.setCourse(course);
score.setStudent(student);
courseinfoService.add(score);
这是我在函数中写的,但是出现错我,说是空指针异常!
我把score.hbm.xml贴上
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="grade.entity.Score" table="score">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<many-to-one name="student" class="baseInfo.entity.Student" fetch="select">
<column name="student_no" not-null="true" />
</many-to-one>
<many-to-one name="course" class="baseInfo.entity.Course" fetch="select">
<column name="course_no" not-null="true" />
</many-to-one>
<property name="credit" type="java.lang.Float">
<column name="credit" precision="53" scale="0" />
</property>
<property name="studentScore" type="java.lang.Float">
<column name="student_score" precision="53" scale="0" not-null="true" />
</property>
<property name="scoreflag" type="java.lang.Integer">
<column name="scoreflag" not-null="true"/>
</property>
</class>
</hibernate-mapping>
希望大家多多帮忙,谢谢了.
我的分数不太多,我自己留个零头,整数给你们,谢谢!