Hibernate - получить запись, где год присутствует в наборе дат - PullRequest
0 голосов
/ 23 октября 2018

Модель

@Entity
@Table(name = "calendar", schema = "master")
public class Calendar implements Serializable {

    private static final long serialVersionUID = -8537804959644622294L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "calender_id")
    private long calendarId;
    @ManyToOne(targetEntity = SittingLocation.class, cascade = CascadeType.MERGE)
    @JoinColumn(name = "sitting_location_id", referencedColumnName = "sitting_location_id")
    private SittingLocation sittingLocation;
    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "calender_date", schema = "master", joinColumns = @JoinColumn(name = "calender_id"))
    @Temporal(TemporalType.DATE)
    @DateTimeFormat(pattern = "dd-MM-yyyy")
    @Column(name = "calender_date")
    private Set<Date> dates = new LinkedHashSet<>();

    public Calendar() {
        this.calendarId = 0;
        this.sittingLocation = null;
        this.dates = null;
    }
\\getter and setter
}

DAO

    @SuppressWarnings("unchecked")
        @Override
        public List<Calendar> listCalendarByYear(SittingLocation sittingLocation,int year) {
            try {
                Query query = sessionFactory.getCurrentSession()
                        .createQuery("FROM Calendar c WHERE c.sittingLocation=:sittingLocation AND :year in elements(YEAR(c.dates))");
                query.setParameter("sittingLocation", sittingLocation);
                query.setParameter("year", year);
                return query.getResultList();
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

Я застрял на этой неделе на неделю.я какое решение, что я могу получить запись, проверяя данный год присутствует в наборе дат.любая замена для запроса "ИЗ календаря c ГДЕ c.sittingLocation =: SittingLocation AND: год в элементах (YEAR (c.dates))" ".

, пожалуйста, помогите.

Заранее спасибо.

...