Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.dao.dto;
- import com.example.dao.impl.jpa.AbstractJpaDAO;
- import javax.persistence.*;
- import java.io.Serializable;
- @Entity
- @Table(name = "widgets")
- @NamedNativeQuery(name = "findTopVotedWidgetsByVisitor",
- query =
- "SELECT" +
- " widgets.label_id, " +
- " widgets.name, " +
- " widgets.description " +
- " VotesByWidgetandVisitor.numVotes as votes" +
- " FROM widgets" +
- " JOIN (" +
- " SELECT" +
- " answers.label_id," +
- " count(*) AS numVotes" +
- " FROM votes" +
- " JOIN answers ON votes.item_id = answers.answer_id" +
- " JOIN questions ON answers.question_id = questions.question_id" +
- " WHERE questions.event_id = :eventId" +
- " AND votes.visitor_id = cast(trim(:visitorId) as uuid)" +
- " GROUP BY answers.label_id, votes.visitor_id" +
- " ) AS VotesByContribLabelAndVisitor ON widgets.label_id = VotesByWidgetAndVisitor.label_id" +
- " ORDER BY numVotes DESC",
- resultSetMapping = "foomap")
- @SqlResultSetMapping(name="foomap",
- entities=
- @EntityResult(entityClass=WidgetItem.class, fields={
- @FieldResult(name="id", column="label_id"),
- @FieldResult(name="name", column="name"),
- @FieldResult(name="description", column="description")}),
- columns={
- @ColumnResult(name="votes")}
- )
- public class WidgetItem extends AbstractJpaDAO implements Serializable {
- // Mapped
- private long id;
- private String name;
- private String description;
- private Long votes;
- @Id
- @Column(name = "label_id")
- public long getId () {
- return id;
- }
- protected void setId (long id) {
- this.id = id;
- }
- public String getName () {
- return name;
- }
- public void setName (String name) {
- this.name = name;
- }
- public String getDescription () {
- return description;
- }
- public void setDescription (String description) {
- this.description = description;
- }
- @Embedded
- public Long getVotes () {
- return votes;
- }
- public void setVotes(Long votes) {
- this.votes = votes;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement