0

我有一个实体,其中有一个列表。

@ManyToMany(fetch=FetchType.EAGER)
  @JoinTable(name = "subject_group_join",
    joinColumns = {
      @JoinColumn(name="sub_group_id")           
    },
    inverseJoinColumns = {
      @JoinColumn(name="subject_id")
    }
  ) 
List<SubjectEntity> listOfSubjects;

主体实体如下:

@Entity
@Table(name="subject_details")
@NamedNativeQueries({
@NamedNativeQuery(name = "GET_SUBJECT_BY_CLASS",query = "call fetchAllSubjectByClass(:classId,:sessionId)",resultClass = SubjectEntity.class)   ,
@NamedNativeQuery(name = "GET_OPTIONAL_SUBJECT_BY_CLASS",query = "call fetchOptionalSubjectByClass(:classId,:sessionId)",resultClass = SubjectEntity.class),
@NamedNativeQuery(name = "GET_CUMPULSORY_SUBJECT_BY_CLASS_NOT_GROUPED",query = "call fetchAllCumpulsorySubjectByClassNotGrouped(:classId,:sessionId)",resultClass = SubjectEntity.class),
@NamedNativeQuery(name = "GET_OPTIONAL_SUBJECT_BY_CLASS_NOT_GROUPED",query = "call fetchAllOptionalSubjectByClassNotGrouped(:classId,:sessionId)",resultClass = SubjectEntity.class),
})
public class SubjectEntity extends AbstractEntity{


private static final long serialVersionUID = 7320078093064615396L;


@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="subject_id")
private long subjectId;


@Column(name="subject_name",length=32)
private String subjectName;


@Column(name="subject_code",length=32)
private String subjectCode;


@Column(name="description",length=512)
private String description;


@Column(name="subject_status")
private boolean subjectStatus;

当我通过 Hql“从 entity1”获取第一个实体列表时;它没有提供在 subjectEntity 中填充的所有数据,它只是在其中包含 id。

4

1 回答 1

0

我认为很难找到问题,但ManyToMany应该看起来像下面的东西

@ManyToMany
@JoinTable(
  name="EMP_PROJ",
  joinColumns={@JoinColumn(name="EMP_ID", referencedColumnName="ID")},
  inverseJoinColumns={@JoinColumn(name="PROJ_ID", referencedColumnName="ID")})
private List<Project> projects;

referencedColumnName您的情况下,主键列的名称将在哪里。

您可以使用ManyToMany作为参考。

于 2012-09-06T08:36:26.813 回答