【问题标题】:Jquery for hibernate many-to-one while retrieving data检索数据时用于休眠多对一的Jquery
【发布时间】:2016-04-05 13:58:58
【问题描述】:

jquery中的data[i]部分可以写什么来获取课程名称,我写了data[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);
    });
});

【问题讨论】:

    标签: jquery hibernate jsp


    【解决方案1】:

    I found the answer here

    所以我为多对一关系的 getter 添加了托管引用和反向引用注释

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多