原因:java.lang.NullPointerException:HQL QUERY为null

时间:2018-09-05 07:17:41

标签: java hql

休眠查询以检索组织 获取空指针异常 有关如何解决的建议?

StringBuilder queryString = new StringBuilder("SELECT abo.idAbonne ")
            .append(" FROM RoleOrganisationsUtilisateurs rou ")
            .append(" JOIN rou.user u ")
            .append(" JOIN rou.abonnes abo ")
            .append(" WHERE u.idUser = :idUser ");

    Query query = getFilteredCurrentSession().createQuery(queryString.toString());
    query.setParameter("idUser", idUser);

    return query.list();

RoleOrganisationUtilisateur实体

@Entity
@Table(name = "T_ROLE_ORGANISATIONS_UTILISATEURS")
public class RoleOrganisationsUtilisateurs extends  {
private static final long serialVersionUID = -2718251269880448406L;

private static final String COLUMN_ID_ROLE_ORGANISATIONS_UTILISATEURS = "ID_ROLE_ORGANISATIONS_UTILISATEURS";

@Id
@Column(name = RoleOrganisationsUtilisateurs.COLUMN_ID_ROLE_ORGANISATIONS_UTILISATEURS, columnDefinition = "CHAR(32)")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String id;


@ManyToOne
@Index(name = IndexNameUtil.T_ROLE_ORG_UTILISATEURS_ID_USER_IDX)
@JoinColumn(name = "ID_USER")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private User user;

@ManyToOne
@Index(name = IndexNameUtil.T_ROLE_ORG_UTILISATEURS_ID_ROLE_IDX)
@JoinColumn(name = "ID_ROLE")
@NotNull
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private Role role;

@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST,
        CascadeType.MERGE })
@JoinTable(name = "T_ROLE_ORGANISATIONS_UTILISATEURS_LNK_T_ORGANISATION", joinColumns = @JoinColumn(name = "ID_ROLE_ORGANISATIONS_UTILISATEURS", nullable = false), inverseJoinColumns = @JoinColumn(name = "ID_ORGANISATION", nullable = false))
@Filters({ @Filter(name = MarsConstants.SUPPRIME_FILTER), @Filter(name = MarsConstants.MIGRATION_FILTER) })
@OrderBy("nomOrganisation ASC")
@NotAudited
private Set<Organisation> organisations = new HashSet<>();

@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST,
        CascadeType.MERGE })
@JoinTable(name = "T_ROLE_ORGANISATIONS_UTILISATEURS_LNK_T_ABONNE", joinColumns = @JoinColumn(name = "ID_ROLE_ORGANISATIONS_UTILISATEURS", nullable = false), inverseJoinColumns = @JoinColumn(name = "ID_ABONNE", nullable = false))
@Filters({ @Filter(name = MarsConstants.SUPPRIME_FILTER), @Filter(name = MarsConstants.MIGRATION_FILTER) })
@OrderBy("nom ASC")
@AuditJoinTable(name = "T_ROLE_ORGS_USERS_LNK_T_ABONNE_AUD")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private Set<Abonne> abonnes = new HashSet<>();

@Column(name = "BOO_ALL_ORGANISATION")
private Boolean allOrganisations = Boolean.FALSE;

@Column(name = "BOO_ALL_ABONNES")
private Boolean allAbonnes = Boolean.FALSE;

这是Abonne实体

@Entity
@Table(name = "T_ABONNE")
@Audited
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY, region="abonne_entity")
public class Abonne  {


    /**
     *
     */
    private static final long serialVersionUID = -7500240243978256087L;

    @Id
    @Column(name = "ID_ABONNE", columnDefinition = "CHAR(32)")
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    private String idAbonne;

    @Column(name = "LIB_NOM", length = 200, nullable = false)
    private String nom;

    @Column(name = "BOO_ACTIF", nullable = false)
    private Boolean actif;

    @Column(name = "DAT_DATE_EXPIRATION", length = 10)
    @Type(type="utcType")
    private Date dateExpiration;

    @Column(name="NO_MAXIM_DE_UTILISATEURS", length = 5000)
    private Integer noMaxUsers;

获取查询的空指针

  

由以下原因引起:java.lang.NullPointerException:null

我的数据库表包含所有必需的数据 有关如何解决的建议?

0 个答案:

没有答案