Querying specific fields including OneToMany fails












2















@Entity
@Data
public class Soknadwrapper {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
private Soknad soknad;

@OneToMany(mappedBy = "soknadwrapper", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@OrderBy("kundereiseNr desc")
private List<Paaminnelse> paaminnelser = new ArrayList<>();

private LocalDateTime opprettetTidspunkt = LocalDateTime.now();
}

@Entity
@Data
public class Paaminnelse {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
@JoinColumn(name = "paminnelser")
private Soknadwrapper soknadwrapper;

private String emneNokkel;
private String innholdNokkel;
private String beskrivelse;
}


Given the following query:



"select distinct s.soknad, s.paaminnelser, s.opprettetTidspunkt from Soknadwrapper s " +
"ORDER BY s.opprettetTidspunkt DESC"


It generates:



SELECT DISTINCT SOKNADWRAP0_.SOKNAD_ID AS COL_0_0_, .[*] AS COL_1_0_, SOKNADWRAP0_.OPPRETTETTIDSPUNKT AS COL_2_0_, SOKNAD1_.ID AS ID1_9_0_, PAAMINNELS2_.ID AS ID1_7_1_, SOKNAD1_.ANTALLMINDREAARIGEBARN AS ANTALLMI2_9_0_, SOKNAD1_.IPADRESSE AS IPADRESS3_9_0_, SOKNAD1_.KAMPANJEKODE AS KAMPANJE4_9_0_, SOKNAD1_.KAUSJONIST_ID AS KAUSJON23_9_0_, SOKNAD1_.KJOPTBOLIG_ID AS KJOPTBO24_9_0_, SOKNAD1_.LAANEDETALJER_AVDRAGSFRIEAAR AS LAANEDET5_9_0_, SOKNAD1_.LAANEDETALJER_FAKTURADATO AS LAANEDET6_9_0_, SOKNAD1_.LAANEDETALJER_FASTRENTEAAR AS LAANEDET7_9_0_, SOKNAD1_.LAANEDETALJER_LAANEBEHOV AS LAANEDET8_9_0_, SOKNAD1_.LAANEDETALJER_MELLOMFINANSIERING AS LAANEDET9_9_0_, SOKNAD1_.LAANEDETALJER_NEDBETALINGSTID AS LAANEDE10_9_0_, SOKNAD1_.LAANEDETALJER_PRODUKTKODE AS LAANEDE11_9_0_, SOKNAD1_.LAANEDETALJER_TILLEGGSLAANEBELOP AS LAANEDE12_9_0_, SOKNAD1_.LAANEDETALJER_TYPELAAN AS LAANEDE13_9_0_, SOKNAD1_.MARKEDSKODE AS MARKEDS14_9_0_, SOKNAD1_.MARKEDSSPORSMAAL AS MARKEDS15_9_0_, SOKNAD1_.MEDSOKER_ID AS MEDSOKE25_9_0_, SOKNAD1_.OKONOMI_EGENKAPITAL AS OKONOMI16_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ARBEIDSSTATUS AS OKONOMI17_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI18_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ARBEIDSSTATUS AS OKONOMI19_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI20_9_0_, SOKNAD1_.ONSKERBYGNINGSFORSIKRING AS ONSKERB21_9_0_, SOKNAD1_.SOKER_ID AS SOKER_I26_9_0_, SOKNAD1_.SOKNADSFORMAAL AS SOKNADS22_9_0_, PAAMINNELS2_.ANTALLDAGERETTERSISTOPPDATERT AS ANTALLDA2_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTEPOST AS ANTALLUT3_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTSMS AS ANTALLUT4_7_1_, PAAMINNELS2_.BESKRIVELSE AS BESKRIVE5_7_1_, PAAMINNELS2_.EMNENOKKEL AS EMNENOKK6_7_1_, PAAMINNELS2_.INNHOLDNOKKEL AS INNHOLDN7_7_1_, PAAMINNELS2_.KUNDEREISENR AS KUNDEREI8_7_1_, PAAMINNELS2_.SOKER AS SOKER9_7_1_, PAAMINNELS2_.PAMINNELSER AS PAMINNE11_7_1_, PAAMINNELS2_.UTSENDELSE AS UTSENDE10_7_1_ FROM SOKNADWRAPPER SOKNADWRAP0_ INNER JOIN SOKNAD SOKNAD1_ ON SOKNADWRAP0_.SOKNAD_ID=SOKNAD1_.ID INNER JOIN PAAMINNELSE PAAMINNELS2_ ON SOKNADWRAP0_.ID=PAAMINNELS2_.PAMINNELSER ORDER BY SOKNADWRAP0_.OPPRETTETTIDSPUNKT DESC "; expected "*, NOT, EXISTS, INTERSECTS, SELECT, FROM, WITH"; SQL statement:

select distinct soknadwrap0_.soknad_id as col_0_0_, . as col_1_0_, soknadwrap0_.opprettetTidspunkt as col_2_0_, soknad1_.id as id1_9_0_, paaminnels2_.id as id1_7_1_, soknad1_.antallMindreaarigeBarn as antallMi2_9_0_, soknad1_.ipAdresse as ipAdress3_9_0_, soknad1_.kampanjekode as kampanje4_9_0_, soknad1_.kausjonist_id as kausjon23_9_0_, soknad1_.kjoptBolig_id as kjoptBo24_9_0_, soknad1_.laanedetaljer_avdragsfrieAar as laanedet5_9_0_, soknad1_.laanedetaljer_fakturadato as laanedet6_9_0_, soknad1_.laanedetaljer_fastrenteAar as laanedet7_9_0_, soknad1_.laanedetaljer_laanebehov as laanedet8_9_0_, soknad1_.laanedetaljer_mellomfinansiering as laanedet9_9_0_, soknad1_.laanedetaljer_nedbetalingstid as laanede10_9_0_, soknad1_.laanedetaljer_produktkode as laanede11_9_0_, soknad1_.laanedetaljer_tilleggslaanebelop as laanede12_9_0_, soknad1_.laanedetaljer_typeLaan as laanede13_9_0_, soknad1_.markedskode as markeds14_9_0_, soknad1_.markedssporsmaal as markeds15_9_0_, soknad1_.medsoker_id as medsoke25_9_0_, soknad1_.okonomi_egenkapital as okonomi16_9_0_, soknad1_.okonomi_hovedsoker_arbeidsstatus as okonomi17_9_0_, soknad1_.okonomi_hovedsoker_estimertBruttoAarsinntekt as okonomi18_9_0_, soknad1_.okonomi_medsoker_arbeidsstatus as okonomi19_9_0_, soknad1_.okonomi_medsoker_estimertBruttoAarsinntekt as okonomi20_9_0_, soknad1_.onskerBygningsforsikring as onskerB21_9_0_, soknad1_.soker_id as soker_i26_9_0_, soknad1_.soknadsformaal as soknads22_9_0_, paaminnels2_.antallDagerEtterSistOppdatert as antallDa2_7_1_, paaminnels2_.antallUtsendelserSendtEpost as antallUt3_7_1_, paaminnels2_.antallUtsendelserSendtSms as antallUt4_7_1_, paaminnels2_.beskrivelse as beskrive5_7_1_, paaminnels2_.emneNokkel as emneNokk6_7_1_, paaminnels2_.innholdNokkel as innholdN7_7_1_, paaminnels2_.kundereiseNr as kunderei8_7_1_, paaminnels2_.soker as soker9_7_1_, paaminnels2_.paminnelser as paminne11_7_1_, paaminnels2_.utsendelse as utsende10_7_1_ from Soknadwrapper soknadwrap0_ inner join Soknad soknad1_ on soknadwrap0_.soknad_id=soknad1_.id inner join Paaminnelse paaminnels2_ on soknadwrap0_.id=paaminnels2_.paminnelser order by soknadwrap0_.opprettetTidspunkt DESC [42001-197]


I have also tried using a projections but it didn't work.



"select distinct new com.foo.bar.repository.projections.PaaminnelseProj(s.soknad, s.paaminnelser, s.opprettetTidspunkt) from Soknadwrapper s " +
"ORDER BY s.opprettetTidspunkt DESC"

@AllArgsConstructor
@Data
public class PaaminnelseProj {
private final Soknad soknad;
private final SortedSet<Paaminnelse> paaminnelser;
private final LocalDateTime opprettetTidspunkt;
}


But this didn't work either. I got pretty much the same error.
What am I doing wrong? Basically I only want these three fields returned, and not more.



Soknadwrapper has more fields which I have omited for brevitity










share|improve this question





























    2















    @Entity
    @Data
    public class Soknadwrapper {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    private Soknad soknad;

    @OneToMany(mappedBy = "soknadwrapper", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @OrderBy("kundereiseNr desc")
    private List<Paaminnelse> paaminnelser = new ArrayList<>();

    private LocalDateTime opprettetTidspunkt = LocalDateTime.now();
    }

    @Entity
    @Data
    public class Paaminnelse {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
    @JoinColumn(name = "paminnelser")
    private Soknadwrapper soknadwrapper;

    private String emneNokkel;
    private String innholdNokkel;
    private String beskrivelse;
    }


    Given the following query:



    "select distinct s.soknad, s.paaminnelser, s.opprettetTidspunkt from Soknadwrapper s " +
    "ORDER BY s.opprettetTidspunkt DESC"


    It generates:



    SELECT DISTINCT SOKNADWRAP0_.SOKNAD_ID AS COL_0_0_, .[*] AS COL_1_0_, SOKNADWRAP0_.OPPRETTETTIDSPUNKT AS COL_2_0_, SOKNAD1_.ID AS ID1_9_0_, PAAMINNELS2_.ID AS ID1_7_1_, SOKNAD1_.ANTALLMINDREAARIGEBARN AS ANTALLMI2_9_0_, SOKNAD1_.IPADRESSE AS IPADRESS3_9_0_, SOKNAD1_.KAMPANJEKODE AS KAMPANJE4_9_0_, SOKNAD1_.KAUSJONIST_ID AS KAUSJON23_9_0_, SOKNAD1_.KJOPTBOLIG_ID AS KJOPTBO24_9_0_, SOKNAD1_.LAANEDETALJER_AVDRAGSFRIEAAR AS LAANEDET5_9_0_, SOKNAD1_.LAANEDETALJER_FAKTURADATO AS LAANEDET6_9_0_, SOKNAD1_.LAANEDETALJER_FASTRENTEAAR AS LAANEDET7_9_0_, SOKNAD1_.LAANEDETALJER_LAANEBEHOV AS LAANEDET8_9_0_, SOKNAD1_.LAANEDETALJER_MELLOMFINANSIERING AS LAANEDET9_9_0_, SOKNAD1_.LAANEDETALJER_NEDBETALINGSTID AS LAANEDE10_9_0_, SOKNAD1_.LAANEDETALJER_PRODUKTKODE AS LAANEDE11_9_0_, SOKNAD1_.LAANEDETALJER_TILLEGGSLAANEBELOP AS LAANEDE12_9_0_, SOKNAD1_.LAANEDETALJER_TYPELAAN AS LAANEDE13_9_0_, SOKNAD1_.MARKEDSKODE AS MARKEDS14_9_0_, SOKNAD1_.MARKEDSSPORSMAAL AS MARKEDS15_9_0_, SOKNAD1_.MEDSOKER_ID AS MEDSOKE25_9_0_, SOKNAD1_.OKONOMI_EGENKAPITAL AS OKONOMI16_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ARBEIDSSTATUS AS OKONOMI17_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI18_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ARBEIDSSTATUS AS OKONOMI19_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI20_9_0_, SOKNAD1_.ONSKERBYGNINGSFORSIKRING AS ONSKERB21_9_0_, SOKNAD1_.SOKER_ID AS SOKER_I26_9_0_, SOKNAD1_.SOKNADSFORMAAL AS SOKNADS22_9_0_, PAAMINNELS2_.ANTALLDAGERETTERSISTOPPDATERT AS ANTALLDA2_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTEPOST AS ANTALLUT3_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTSMS AS ANTALLUT4_7_1_, PAAMINNELS2_.BESKRIVELSE AS BESKRIVE5_7_1_, PAAMINNELS2_.EMNENOKKEL AS EMNENOKK6_7_1_, PAAMINNELS2_.INNHOLDNOKKEL AS INNHOLDN7_7_1_, PAAMINNELS2_.KUNDEREISENR AS KUNDEREI8_7_1_, PAAMINNELS2_.SOKER AS SOKER9_7_1_, PAAMINNELS2_.PAMINNELSER AS PAMINNE11_7_1_, PAAMINNELS2_.UTSENDELSE AS UTSENDE10_7_1_ FROM SOKNADWRAPPER SOKNADWRAP0_ INNER JOIN SOKNAD SOKNAD1_ ON SOKNADWRAP0_.SOKNAD_ID=SOKNAD1_.ID INNER JOIN PAAMINNELSE PAAMINNELS2_ ON SOKNADWRAP0_.ID=PAAMINNELS2_.PAMINNELSER ORDER BY SOKNADWRAP0_.OPPRETTETTIDSPUNKT DESC "; expected "*, NOT, EXISTS, INTERSECTS, SELECT, FROM, WITH"; SQL statement:

    select distinct soknadwrap0_.soknad_id as col_0_0_, . as col_1_0_, soknadwrap0_.opprettetTidspunkt as col_2_0_, soknad1_.id as id1_9_0_, paaminnels2_.id as id1_7_1_, soknad1_.antallMindreaarigeBarn as antallMi2_9_0_, soknad1_.ipAdresse as ipAdress3_9_0_, soknad1_.kampanjekode as kampanje4_9_0_, soknad1_.kausjonist_id as kausjon23_9_0_, soknad1_.kjoptBolig_id as kjoptBo24_9_0_, soknad1_.laanedetaljer_avdragsfrieAar as laanedet5_9_0_, soknad1_.laanedetaljer_fakturadato as laanedet6_9_0_, soknad1_.laanedetaljer_fastrenteAar as laanedet7_9_0_, soknad1_.laanedetaljer_laanebehov as laanedet8_9_0_, soknad1_.laanedetaljer_mellomfinansiering as laanedet9_9_0_, soknad1_.laanedetaljer_nedbetalingstid as laanede10_9_0_, soknad1_.laanedetaljer_produktkode as laanede11_9_0_, soknad1_.laanedetaljer_tilleggslaanebelop as laanede12_9_0_, soknad1_.laanedetaljer_typeLaan as laanede13_9_0_, soknad1_.markedskode as markeds14_9_0_, soknad1_.markedssporsmaal as markeds15_9_0_, soknad1_.medsoker_id as medsoke25_9_0_, soknad1_.okonomi_egenkapital as okonomi16_9_0_, soknad1_.okonomi_hovedsoker_arbeidsstatus as okonomi17_9_0_, soknad1_.okonomi_hovedsoker_estimertBruttoAarsinntekt as okonomi18_9_0_, soknad1_.okonomi_medsoker_arbeidsstatus as okonomi19_9_0_, soknad1_.okonomi_medsoker_estimertBruttoAarsinntekt as okonomi20_9_0_, soknad1_.onskerBygningsforsikring as onskerB21_9_0_, soknad1_.soker_id as soker_i26_9_0_, soknad1_.soknadsformaal as soknads22_9_0_, paaminnels2_.antallDagerEtterSistOppdatert as antallDa2_7_1_, paaminnels2_.antallUtsendelserSendtEpost as antallUt3_7_1_, paaminnels2_.antallUtsendelserSendtSms as antallUt4_7_1_, paaminnels2_.beskrivelse as beskrive5_7_1_, paaminnels2_.emneNokkel as emneNokk6_7_1_, paaminnels2_.innholdNokkel as innholdN7_7_1_, paaminnels2_.kundereiseNr as kunderei8_7_1_, paaminnels2_.soker as soker9_7_1_, paaminnels2_.paminnelser as paminne11_7_1_, paaminnels2_.utsendelse as utsende10_7_1_ from Soknadwrapper soknadwrap0_ inner join Soknad soknad1_ on soknadwrap0_.soknad_id=soknad1_.id inner join Paaminnelse paaminnels2_ on soknadwrap0_.id=paaminnels2_.paminnelser order by soknadwrap0_.opprettetTidspunkt DESC [42001-197]


    I have also tried using a projections but it didn't work.



    "select distinct new com.foo.bar.repository.projections.PaaminnelseProj(s.soknad, s.paaminnelser, s.opprettetTidspunkt) from Soknadwrapper s " +
    "ORDER BY s.opprettetTidspunkt DESC"

    @AllArgsConstructor
    @Data
    public class PaaminnelseProj {
    private final Soknad soknad;
    private final SortedSet<Paaminnelse> paaminnelser;
    private final LocalDateTime opprettetTidspunkt;
    }


    But this didn't work either. I got pretty much the same error.
    What am I doing wrong? Basically I only want these three fields returned, and not more.



    Soknadwrapper has more fields which I have omited for brevitity










    share|improve this question



























      2












      2








      2








      @Entity
      @Data
      public class Soknadwrapper {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;

      @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
      private Soknad soknad;

      @OneToMany(mappedBy = "soknadwrapper", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
      @OrderBy("kundereiseNr desc")
      private List<Paaminnelse> paaminnelser = new ArrayList<>();

      private LocalDateTime opprettetTidspunkt = LocalDateTime.now();
      }

      @Entity
      @Data
      public class Paaminnelse {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;

      @ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
      @JoinColumn(name = "paminnelser")
      private Soknadwrapper soknadwrapper;

      private String emneNokkel;
      private String innholdNokkel;
      private String beskrivelse;
      }


      Given the following query:



      "select distinct s.soknad, s.paaminnelser, s.opprettetTidspunkt from Soknadwrapper s " +
      "ORDER BY s.opprettetTidspunkt DESC"


      It generates:



      SELECT DISTINCT SOKNADWRAP0_.SOKNAD_ID AS COL_0_0_, .[*] AS COL_1_0_, SOKNADWRAP0_.OPPRETTETTIDSPUNKT AS COL_2_0_, SOKNAD1_.ID AS ID1_9_0_, PAAMINNELS2_.ID AS ID1_7_1_, SOKNAD1_.ANTALLMINDREAARIGEBARN AS ANTALLMI2_9_0_, SOKNAD1_.IPADRESSE AS IPADRESS3_9_0_, SOKNAD1_.KAMPANJEKODE AS KAMPANJE4_9_0_, SOKNAD1_.KAUSJONIST_ID AS KAUSJON23_9_0_, SOKNAD1_.KJOPTBOLIG_ID AS KJOPTBO24_9_0_, SOKNAD1_.LAANEDETALJER_AVDRAGSFRIEAAR AS LAANEDET5_9_0_, SOKNAD1_.LAANEDETALJER_FAKTURADATO AS LAANEDET6_9_0_, SOKNAD1_.LAANEDETALJER_FASTRENTEAAR AS LAANEDET7_9_0_, SOKNAD1_.LAANEDETALJER_LAANEBEHOV AS LAANEDET8_9_0_, SOKNAD1_.LAANEDETALJER_MELLOMFINANSIERING AS LAANEDET9_9_0_, SOKNAD1_.LAANEDETALJER_NEDBETALINGSTID AS LAANEDE10_9_0_, SOKNAD1_.LAANEDETALJER_PRODUKTKODE AS LAANEDE11_9_0_, SOKNAD1_.LAANEDETALJER_TILLEGGSLAANEBELOP AS LAANEDE12_9_0_, SOKNAD1_.LAANEDETALJER_TYPELAAN AS LAANEDE13_9_0_, SOKNAD1_.MARKEDSKODE AS MARKEDS14_9_0_, SOKNAD1_.MARKEDSSPORSMAAL AS MARKEDS15_9_0_, SOKNAD1_.MEDSOKER_ID AS MEDSOKE25_9_0_, SOKNAD1_.OKONOMI_EGENKAPITAL AS OKONOMI16_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ARBEIDSSTATUS AS OKONOMI17_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI18_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ARBEIDSSTATUS AS OKONOMI19_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI20_9_0_, SOKNAD1_.ONSKERBYGNINGSFORSIKRING AS ONSKERB21_9_0_, SOKNAD1_.SOKER_ID AS SOKER_I26_9_0_, SOKNAD1_.SOKNADSFORMAAL AS SOKNADS22_9_0_, PAAMINNELS2_.ANTALLDAGERETTERSISTOPPDATERT AS ANTALLDA2_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTEPOST AS ANTALLUT3_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTSMS AS ANTALLUT4_7_1_, PAAMINNELS2_.BESKRIVELSE AS BESKRIVE5_7_1_, PAAMINNELS2_.EMNENOKKEL AS EMNENOKK6_7_1_, PAAMINNELS2_.INNHOLDNOKKEL AS INNHOLDN7_7_1_, PAAMINNELS2_.KUNDEREISENR AS KUNDEREI8_7_1_, PAAMINNELS2_.SOKER AS SOKER9_7_1_, PAAMINNELS2_.PAMINNELSER AS PAMINNE11_7_1_, PAAMINNELS2_.UTSENDELSE AS UTSENDE10_7_1_ FROM SOKNADWRAPPER SOKNADWRAP0_ INNER JOIN SOKNAD SOKNAD1_ ON SOKNADWRAP0_.SOKNAD_ID=SOKNAD1_.ID INNER JOIN PAAMINNELSE PAAMINNELS2_ ON SOKNADWRAP0_.ID=PAAMINNELS2_.PAMINNELSER ORDER BY SOKNADWRAP0_.OPPRETTETTIDSPUNKT DESC "; expected "*, NOT, EXISTS, INTERSECTS, SELECT, FROM, WITH"; SQL statement:

      select distinct soknadwrap0_.soknad_id as col_0_0_, . as col_1_0_, soknadwrap0_.opprettetTidspunkt as col_2_0_, soknad1_.id as id1_9_0_, paaminnels2_.id as id1_7_1_, soknad1_.antallMindreaarigeBarn as antallMi2_9_0_, soknad1_.ipAdresse as ipAdress3_9_0_, soknad1_.kampanjekode as kampanje4_9_0_, soknad1_.kausjonist_id as kausjon23_9_0_, soknad1_.kjoptBolig_id as kjoptBo24_9_0_, soknad1_.laanedetaljer_avdragsfrieAar as laanedet5_9_0_, soknad1_.laanedetaljer_fakturadato as laanedet6_9_0_, soknad1_.laanedetaljer_fastrenteAar as laanedet7_9_0_, soknad1_.laanedetaljer_laanebehov as laanedet8_9_0_, soknad1_.laanedetaljer_mellomfinansiering as laanedet9_9_0_, soknad1_.laanedetaljer_nedbetalingstid as laanede10_9_0_, soknad1_.laanedetaljer_produktkode as laanede11_9_0_, soknad1_.laanedetaljer_tilleggslaanebelop as laanede12_9_0_, soknad1_.laanedetaljer_typeLaan as laanede13_9_0_, soknad1_.markedskode as markeds14_9_0_, soknad1_.markedssporsmaal as markeds15_9_0_, soknad1_.medsoker_id as medsoke25_9_0_, soknad1_.okonomi_egenkapital as okonomi16_9_0_, soknad1_.okonomi_hovedsoker_arbeidsstatus as okonomi17_9_0_, soknad1_.okonomi_hovedsoker_estimertBruttoAarsinntekt as okonomi18_9_0_, soknad1_.okonomi_medsoker_arbeidsstatus as okonomi19_9_0_, soknad1_.okonomi_medsoker_estimertBruttoAarsinntekt as okonomi20_9_0_, soknad1_.onskerBygningsforsikring as onskerB21_9_0_, soknad1_.soker_id as soker_i26_9_0_, soknad1_.soknadsformaal as soknads22_9_0_, paaminnels2_.antallDagerEtterSistOppdatert as antallDa2_7_1_, paaminnels2_.antallUtsendelserSendtEpost as antallUt3_7_1_, paaminnels2_.antallUtsendelserSendtSms as antallUt4_7_1_, paaminnels2_.beskrivelse as beskrive5_7_1_, paaminnels2_.emneNokkel as emneNokk6_7_1_, paaminnels2_.innholdNokkel as innholdN7_7_1_, paaminnels2_.kundereiseNr as kunderei8_7_1_, paaminnels2_.soker as soker9_7_1_, paaminnels2_.paminnelser as paminne11_7_1_, paaminnels2_.utsendelse as utsende10_7_1_ from Soknadwrapper soknadwrap0_ inner join Soknad soknad1_ on soknadwrap0_.soknad_id=soknad1_.id inner join Paaminnelse paaminnels2_ on soknadwrap0_.id=paaminnels2_.paminnelser order by soknadwrap0_.opprettetTidspunkt DESC [42001-197]


      I have also tried using a projections but it didn't work.



      "select distinct new com.foo.bar.repository.projections.PaaminnelseProj(s.soknad, s.paaminnelser, s.opprettetTidspunkt) from Soknadwrapper s " +
      "ORDER BY s.opprettetTidspunkt DESC"

      @AllArgsConstructor
      @Data
      public class PaaminnelseProj {
      private final Soknad soknad;
      private final SortedSet<Paaminnelse> paaminnelser;
      private final LocalDateTime opprettetTidspunkt;
      }


      But this didn't work either. I got pretty much the same error.
      What am I doing wrong? Basically I only want these three fields returned, and not more.



      Soknadwrapper has more fields which I have omited for brevitity










      share|improve this question
















      @Entity
      @Data
      public class Soknadwrapper {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;

      @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
      private Soknad soknad;

      @OneToMany(mappedBy = "soknadwrapper", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
      @OrderBy("kundereiseNr desc")
      private List<Paaminnelse> paaminnelser = new ArrayList<>();

      private LocalDateTime opprettetTidspunkt = LocalDateTime.now();
      }

      @Entity
      @Data
      public class Paaminnelse {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;

      @ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
      @JoinColumn(name = "paminnelser")
      private Soknadwrapper soknadwrapper;

      private String emneNokkel;
      private String innholdNokkel;
      private String beskrivelse;
      }


      Given the following query:



      "select distinct s.soknad, s.paaminnelser, s.opprettetTidspunkt from Soknadwrapper s " +
      "ORDER BY s.opprettetTidspunkt DESC"


      It generates:



      SELECT DISTINCT SOKNADWRAP0_.SOKNAD_ID AS COL_0_0_, .[*] AS COL_1_0_, SOKNADWRAP0_.OPPRETTETTIDSPUNKT AS COL_2_0_, SOKNAD1_.ID AS ID1_9_0_, PAAMINNELS2_.ID AS ID1_7_1_, SOKNAD1_.ANTALLMINDREAARIGEBARN AS ANTALLMI2_9_0_, SOKNAD1_.IPADRESSE AS IPADRESS3_9_0_, SOKNAD1_.KAMPANJEKODE AS KAMPANJE4_9_0_, SOKNAD1_.KAUSJONIST_ID AS KAUSJON23_9_0_, SOKNAD1_.KJOPTBOLIG_ID AS KJOPTBO24_9_0_, SOKNAD1_.LAANEDETALJER_AVDRAGSFRIEAAR AS LAANEDET5_9_0_, SOKNAD1_.LAANEDETALJER_FAKTURADATO AS LAANEDET6_9_0_, SOKNAD1_.LAANEDETALJER_FASTRENTEAAR AS LAANEDET7_9_0_, SOKNAD1_.LAANEDETALJER_LAANEBEHOV AS LAANEDET8_9_0_, SOKNAD1_.LAANEDETALJER_MELLOMFINANSIERING AS LAANEDET9_9_0_, SOKNAD1_.LAANEDETALJER_NEDBETALINGSTID AS LAANEDE10_9_0_, SOKNAD1_.LAANEDETALJER_PRODUKTKODE AS LAANEDE11_9_0_, SOKNAD1_.LAANEDETALJER_TILLEGGSLAANEBELOP AS LAANEDE12_9_0_, SOKNAD1_.LAANEDETALJER_TYPELAAN AS LAANEDE13_9_0_, SOKNAD1_.MARKEDSKODE AS MARKEDS14_9_0_, SOKNAD1_.MARKEDSSPORSMAAL AS MARKEDS15_9_0_, SOKNAD1_.MEDSOKER_ID AS MEDSOKE25_9_0_, SOKNAD1_.OKONOMI_EGENKAPITAL AS OKONOMI16_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ARBEIDSSTATUS AS OKONOMI17_9_0_, SOKNAD1_.OKONOMI_HOVEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI18_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ARBEIDSSTATUS AS OKONOMI19_9_0_, SOKNAD1_.OKONOMI_MEDSOKER_ESTIMERTBRUTTOAARSINNTEKT AS OKONOMI20_9_0_, SOKNAD1_.ONSKERBYGNINGSFORSIKRING AS ONSKERB21_9_0_, SOKNAD1_.SOKER_ID AS SOKER_I26_9_0_, SOKNAD1_.SOKNADSFORMAAL AS SOKNADS22_9_0_, PAAMINNELS2_.ANTALLDAGERETTERSISTOPPDATERT AS ANTALLDA2_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTEPOST AS ANTALLUT3_7_1_, PAAMINNELS2_.ANTALLUTSENDELSERSENDTSMS AS ANTALLUT4_7_1_, PAAMINNELS2_.BESKRIVELSE AS BESKRIVE5_7_1_, PAAMINNELS2_.EMNENOKKEL AS EMNENOKK6_7_1_, PAAMINNELS2_.INNHOLDNOKKEL AS INNHOLDN7_7_1_, PAAMINNELS2_.KUNDEREISENR AS KUNDEREI8_7_1_, PAAMINNELS2_.SOKER AS SOKER9_7_1_, PAAMINNELS2_.PAMINNELSER AS PAMINNE11_7_1_, PAAMINNELS2_.UTSENDELSE AS UTSENDE10_7_1_ FROM SOKNADWRAPPER SOKNADWRAP0_ INNER JOIN SOKNAD SOKNAD1_ ON SOKNADWRAP0_.SOKNAD_ID=SOKNAD1_.ID INNER JOIN PAAMINNELSE PAAMINNELS2_ ON SOKNADWRAP0_.ID=PAAMINNELS2_.PAMINNELSER ORDER BY SOKNADWRAP0_.OPPRETTETTIDSPUNKT DESC "; expected "*, NOT, EXISTS, INTERSECTS, SELECT, FROM, WITH"; SQL statement:

      select distinct soknadwrap0_.soknad_id as col_0_0_, . as col_1_0_, soknadwrap0_.opprettetTidspunkt as col_2_0_, soknad1_.id as id1_9_0_, paaminnels2_.id as id1_7_1_, soknad1_.antallMindreaarigeBarn as antallMi2_9_0_, soknad1_.ipAdresse as ipAdress3_9_0_, soknad1_.kampanjekode as kampanje4_9_0_, soknad1_.kausjonist_id as kausjon23_9_0_, soknad1_.kjoptBolig_id as kjoptBo24_9_0_, soknad1_.laanedetaljer_avdragsfrieAar as laanedet5_9_0_, soknad1_.laanedetaljer_fakturadato as laanedet6_9_0_, soknad1_.laanedetaljer_fastrenteAar as laanedet7_9_0_, soknad1_.laanedetaljer_laanebehov as laanedet8_9_0_, soknad1_.laanedetaljer_mellomfinansiering as laanedet9_9_0_, soknad1_.laanedetaljer_nedbetalingstid as laanede10_9_0_, soknad1_.laanedetaljer_produktkode as laanede11_9_0_, soknad1_.laanedetaljer_tilleggslaanebelop as laanede12_9_0_, soknad1_.laanedetaljer_typeLaan as laanede13_9_0_, soknad1_.markedskode as markeds14_9_0_, soknad1_.markedssporsmaal as markeds15_9_0_, soknad1_.medsoker_id as medsoke25_9_0_, soknad1_.okonomi_egenkapital as okonomi16_9_0_, soknad1_.okonomi_hovedsoker_arbeidsstatus as okonomi17_9_0_, soknad1_.okonomi_hovedsoker_estimertBruttoAarsinntekt as okonomi18_9_0_, soknad1_.okonomi_medsoker_arbeidsstatus as okonomi19_9_0_, soknad1_.okonomi_medsoker_estimertBruttoAarsinntekt as okonomi20_9_0_, soknad1_.onskerBygningsforsikring as onskerB21_9_0_, soknad1_.soker_id as soker_i26_9_0_, soknad1_.soknadsformaal as soknads22_9_0_, paaminnels2_.antallDagerEtterSistOppdatert as antallDa2_7_1_, paaminnels2_.antallUtsendelserSendtEpost as antallUt3_7_1_, paaminnels2_.antallUtsendelserSendtSms as antallUt4_7_1_, paaminnels2_.beskrivelse as beskrive5_7_1_, paaminnels2_.emneNokkel as emneNokk6_7_1_, paaminnels2_.innholdNokkel as innholdN7_7_1_, paaminnels2_.kundereiseNr as kunderei8_7_1_, paaminnels2_.soker as soker9_7_1_, paaminnels2_.paminnelser as paminne11_7_1_, paaminnels2_.utsendelse as utsende10_7_1_ from Soknadwrapper soknadwrap0_ inner join Soknad soknad1_ on soknadwrap0_.soknad_id=soknad1_.id inner join Paaminnelse paaminnels2_ on soknadwrap0_.id=paaminnels2_.paminnelser order by soknadwrap0_.opprettetTidspunkt DESC [42001-197]


      I have also tried using a projections but it didn't work.



      "select distinct new com.foo.bar.repository.projections.PaaminnelseProj(s.soknad, s.paaminnelser, s.opprettetTidspunkt) from Soknadwrapper s " +
      "ORDER BY s.opprettetTidspunkt DESC"

      @AllArgsConstructor
      @Data
      public class PaaminnelseProj {
      private final Soknad soknad;
      private final SortedSet<Paaminnelse> paaminnelser;
      private final LocalDateTime opprettetTidspunkt;
      }


      But this didn't work either. I got pretty much the same error.
      What am I doing wrong? Basically I only want these three fields returned, and not more.



      Soknadwrapper has more fields which I have omited for brevitity







      java hibernate jpa spring-data jpa-2.0






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 12:59







      Shervin Asgari

















      asked Jan 2 at 12:53









      Shervin AsgariShervin Asgari

      15k2580128




      15k2580128
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006755%2fquerying-specific-fields-including-onetomany-fails%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006755%2fquerying-specific-fields-including-onetomany-fails%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules