Код: Выделить всё
@Entity
@Table
@IdClass(SzczegolyZamowieniaId.class)
public class SzczegolyZamowienia {
int ilosc;
@Id
@ManyToOne
Zamowienie zamowienie;
@Id
@ManyToOne
Produkt produkt;
//getters/setters/constructors
}
@Entity
@Table
public class Zamowienie {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
LocalDate data;
@ManyToOne
Klient klient;
//getters/setters/constructors
}
@Entity
@Table
public class Produkt {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
String nazwa;
String opis;
int cena;
//getters/setters/constructors
}
Код: Выделить всё
public interface TopProdukt {
public int getIlosc();
public String getNazwa();
public String getOpis();
public int getCena();
}
Код: Выделить всё
@Query("select sum(sz.ilosc) as Ilosc,sz.produkt.nazwa as Nazwa,sz.produkt.opis as Opis,sz.produkt.cena as Cena from SzczegolyZamowienia sz group by sz.produkt order by sum(sz.ilosc) desc")
public Collection topProdukt();
Код: Выделить всё
There was an unexpected error (type=Internal Server Error, status=500).
Could not write JSON: Null return value from advice does not match primitive return type for: public abstract int org.example.serwisy.projekcja.TopProdukt.getCena()
org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Null return value from advice does not match primitive return type for: public abstract int org.example.serwisy.projekcja.TopProdukt.getCena()
Код: Выделить всё
@Query(value = """
select sum(sz.ilosc) as Ilosc,p.nazwa as Nazwa,p.opis as Opis,p.cena as Cena
from Szczegoly_Zamowienia sz
INNER JOIN Zamowienie z ON z.id=sz.zamowienie_id
INNER JOIN Produkt p ON p.id=sz.produkt_id
group by p.id
order by sum(sz.ilosc) desc
""",nativeQuery = true)
public Collection topProdukt();
Та же база данных, те же данные, Springboot 4.0.5