0

I saw huge amount of similar questions here but they didn't give me an answer, probably I missed one, which covers my case. So here is the part of code which produces an Exception:

<c:forEach var="srPeer" items="${preset_groups}">
    $("#preset_checkbox_" + "<c:out value='${srPeer.srPeerPK.peerGroupId}' />").attr("checked", true);
</c:forEach>

javax.el.PropertyNotFoundException: Property 'srPeerPK' not found on type java.lang.String

preset_groups variable stores in a Session. I set in in this way:

Set<SrPeer> presetGroups = srPeerDao.findSelectedPresetPeerGroupsByFirm(intFirmID);
session.setAttribute(SessionAttributes.PRESET_GROUPS, presetGroups);

SrPeer class:

@Entity
@Table(name = "SR_PEERS")
public class SrPeer implements Serializable {
    private static final long serialVersionUID = -6119498549478635542L;

    @EmbeddedId
    private SrPeerPK srPeerPK;

    @Column(name = "PEERGROUPNAME_UI")
    private String peerGroupNameUi;

    @Column(name = "PEER_FIRM_DATA_VALID")
    private String peerFirmDataValid;

    @Column(name = "PEER_FIRM_NAME")
    private String peerFirmName;

    @Column(name = "REPORT_VERSION")
    private String reportVersion;

    //Getters and Setters
}

SrPeerPK class:

@Embeddable
public class SrPeerPK implements Serializable {
    private static final long serialVersionUID = -4539516420308504052L;

    @Column(name = "FIRM_ID")
    private Integer firmId;

    @Column(name = "PEERGROUP_ID")
    private Integer peerGroupId;

    @Column(name = "PEER_FIRM_ID")
    private Integer peerFirmId;

    //Getters and Setters
}

Any guess what is the problem?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Petr Shypila
  • 1,449
  • 9
  • 27
  • 47
  • Usually, exceptions don't lie. Take a step back and inspect `presetGroups` variable before setting it as request attribute. Use a debugger breakpoint or poor man's system.out.println and inspect/print each list item. Does the list really contain `SrPeer` instances as implied by the generic type (which possibly has an unchecked cast inside `findSelectedPresetPeerGroupsByFirm()` method)? Or are they actually `String` instances as implied by the exception? – BalusC May 19 '16 at 12:30
  • @BalusC Thank you. You were right. Spring Data magic. I tried to use sql distinct keyword in JPA queries. It returned be just a distinct string instead of a whole object. – Petr Shypila May 19 '16 at 14:14

0 Answers0