Jquery用于在检索数据时多对一地进行休眠

时间:2016-04-05 13:58:58

标签: jquery hibernate jsp

什么可以写入数据[i]部分在jquery获取课程名称,我写了数据[i] .course.coursename但它没有工作

以下是我的模特,教育和课程;

@Entity
@Table(name = "Education", schema = "xxx")
public class Education implements java.io.Serializable {

@JsonBackReference
private  Course course;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "COURSEID", nullable = false)
public Course getCourse() {
    return this.course;
}

public void setCourse (Course course) {
    this.course = course;
}

@Entity
@Table(name = "COURSE", schema = "xxx")
public class Course implements java.io.Serializable {

@JsonManagedReference
private Set<Education> educations = new HashSet<Education>(0);

@OneToMany(fetch = FetchType.LAZY, mappedBy = "course")
public Set<Education> getEducations() {
    return this.educations;
}

public void setEducations(Set<Education> educations) {
    this.educations = educations;
}

和jquery部分用于级联下拉

$('#departmentid').change(
function() {

    $.getJSON('loadCourse',{
        departmentid : $(this).val()
    }, function(data) {

        var html = '<option value="">----Select Course----</option>';
        var len = data.length;

        for ( var i = 0; i < len; i++) {
            html += '<option value="' + data[i].educationid + '">' + data[i].course.coursename + ' ' + data[i].course.prefix + '</option>';

        }
        html += '</option>';
        $('#educationid').html(html);
    }).error(function(jqXHR, textStatus, errorThrown){ /* assign handler */
        /* alert(jqXHR.responseText) */
        alert(errorThrown);
    });
});

1 个答案:

答案 0 :(得分:0)

I found the answer here

所以我将管理引用和反向引用注释添加到多关系的getter