Code: Select all
@Entity
@Getter
@Setter
@Table(name = "indicator_values")
public class IndicatorValue {
@EmbeddedId
public IndicatorValueId id;
@Column(name = "value")
public BigDecimal value;
public IndicatorValue() {}
public IndicatorValue(
IndicatorValueId id,
BigDecimal value
) {
this.id = id;
this.value = value;
}
// Constructor used for experimentation (invoked in the repository)
public IndicatorValue(
String categoryCode,
String indicatorCode,
BigDecimal value,
LocalDate effectiveDate
) {
this.value = value;
this.id = new IndicatorValueId(categoryCode, indicatorCode, effectiveDate);
}
}
Code: Select all
@Embeddable
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@Getter
@Setter
public class IndicatorValueId implements Serializable {
@Column(name = "category_code")
private String categoryCode;
@Column(name = "indicator_code")
private String indicatorCode;
@Column(name = "effective_date")
private LocalDate effectiveDate;
}
Code: Select all
public interface IndicatorValueRepository extends JpaRepository {
@Query("""
SELECT iv
FROM IndicatorValue iv
WHERE iv.id.indicatorCode = :indicatorCode
AND iv.id.effectiveDate < :effectiveDate
ORDER BY iv.id.effectiveDate DESC
""")
List findByIndicatorCodeBeforeDate(
@Param("indicatorCode") String indicatorCode,
@Param("effectiveDate") LocalDate effectiveDate
);
@Query("""
SELECT NEW by.vezhlivec.normsservice.entity.IndicatorValue(
iv.id.categoryCode,
iv.id.indicatorCode,
iv.value,
iv.id.effectiveDate
)
FROM IndicatorValue iv
WHERE iv.id.indicatorCode = :indicatorCode
AND iv.id.categoryCode IS NULL
AND iv.id.effectiveDate < :effectiveDate
ORDER BY iv.id.effectiveDate DESC
""")
List findByIndicatorCodeBeforeDate1(
@Param("indicatorCode") String indicatorCode,
@Param("effectiveDate") LocalDate effectiveDate
);
List findByIdIndicatorCode(String indicatorCode);
List findByValue(BigDecimal value);
}
In allen anderen Fällen – wenn ich versuche, die Entität oder eine Liste von Entitäten abzurufen – erhalte ich entweder null oder eine Liste mit der richtigen Anzahl von Elementen, aber jedes Element ist es null.
Sogar der Standard findById() gibt null zurück, obwohl der Datensatz definitiv in der Datenbank vorhanden ist.
Hier ist ein Testausschnitt aus dem Dienst
Code: Select all
List iv = indicatorValueRepository.findByIdIndicatorCode("worker_4th_grade_hour_rate_construction");
System.out.println(iv);
List v = indicatorValueRepository.findByValue(new BigDecimal("13.02"));
System.out.println(v);
List iv1 = indicatorValueRepository
.findByIndicatorCodeBeforeDate("worker_4th_grade_hour_rate_construction", period.atDay(1));
System.out.println(iv1);
List iv2 = indicatorValueRepository
.findByIndicatorCodeBeforeDate1("worker_4th_grade_hour_rate_construction", period.atDay(1));
for (IndicatorValue iv3 : iv2) {
log.debug("Код категории: {}, код индикатора: {}, значение: {}, дата: {}",
iv3.getId().getCategoryCode(),
iv3.getId().getIndicatorCode(),
iv3.getValue(),
iv3.getId().getEffectiveDate());
}
Optional iv4 = indicatorValueRepository
.findById(new IndicatorValueId(
null,
"worker_4th_grade_hour_rate_construction",
LocalDate.of(2025, 9, 1)
)
);
System.out.println(iv4.orElse(null));
Code: Select all
2025-11-28T22:28:44.318+03:00 DEBUG 414781 --- [nio-8080-exec-2] org.hibernate.SQL :
select
iv1_0.category_code,
iv1_0.effective_date,
iv1_0.indicator_code,
iv1_0.value
from
indicator_values iv1_0
where
iv1_0.indicator_code=?
2025-11-28T22:28:44.323+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
2025-11-28T22:28:44.324+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
2025-11-28T22:28:44.324+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
[null, null, null]
2025-11-28T22:28:44.326+03:00 DEBUG 414781 --- [nio-8080-exec-2] org.hibernate.SQL :
select
iv1_0.category_code,
iv1_0.effective_date,
iv1_0.indicator_code,
iv1_0.value
from
indicator_values iv1_0
where
iv1_0.value=?
2025-11-28T22:28:44.327+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
2025-11-28T22:28:44.327+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
2025-11-28T22:28:44.327+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
2025-11-28T22:28:44.327+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
2025-11-28T22:28:44.327+03:00 TRACE 414781 --- [nio-8080-exec-2] org.hibernate.orm.jdbc.extract : extracted value (1:VARCHAR) -> [null]
[null, null, null, null, null]
2025-11-28T22:28:44.330+03:00 DEBUG 414781 --- [nio-8080-exec-2] org.hibernate.SQL :
select
iv1_0.category_code,
iv1_0.effective_date,
iv1_0.indicator_code,
iv1_0.value
from
indicator_values iv1_0
where
iv1_0.indicator_code=?
and iv1_0.effective_date
Mobile version