i'M HAVING A TROUBLE WITH AN PROJECT, AN EXCEPTIONS IS RETURNED TO ME, I tried editing the model by trying to remove the nullable = true constraint, but the porblem persists
org.hibernate.PropertyValueException: not-null property references a null or transient
value
nested exception is org.hibernate.PropertyValueException: not-null property references
a null or transient value
org.springframework.dao.DataIntegrityViolationException: not-null property references a
null or transient value :
I attach below the structure of my project
Controller
@Controller
public class TemperatureController {
@Autowired
private TemperatureService temperatureService;
@RequestMapping(value="/", method= RequestMethod.GET) // inserisco il controllo per la
chiamata alla pagina principale
public ModelAndView homePage() { // creo un modelandview
ModelAndView mv = new ModelAndView(); // creo un'istanza del modelandView
mv.setViewName("home"); // setto il nome dell'istanza
List<InfoMeteo> listaIndicatoriMeteo = temperatureService.getAll();
mv.addObject("listaIndicatoriMeteo",listaIndicatoriMeteo);
mv.addObject("indicatoreMeteo", new InfoMeteo()); // creo la lista
return mv; // ritorno l'istanza
}
@RequestMapping(value="/", method= RequestMethod.POST)
public ModelAndView saveIndicatoriMeteo(InfoMeteo indicatoreMeteo) {
temperatureService.saveIndicatoriMeteo(indicatoreMeteo);
return new ModelAndView("redirect:/");
}
}
Model
@Entity
@Table(name="gestioneindicatorimeteo")
public class InfoMeteo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO) // uso l'autoincrement
private long id;
@Column(name="Data")
private Date Data;
@Column(name="TemperaturaMax", nullable= false)
private byte TemperaturaGiornalieraMax;
@Column(name="TemperaturaMin", nullable= false)
private byte TemperaturaGiornalieraMin;
@Column(name="precipitazioni")
private String precipitazioni;
@Column(name="Quantità", nullable= false)
private byte quantitaprec;
@Column(name="Tempo", nullable= false)
private String tempo;
@Column(name="URMax", nullable= false)
private byte umiditaMax;
@Column(name="URMin", nullable= false)
private byte umiditaMin;
@Column(name="WSPDMax", nullable= false)
private short velocitaVentoMax;
@Column(name="WSPDMin", nullable= false)
private short velocitaVentoMin;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Date getData() {
return Data;
}
public void setData(Date data) {
Data = data;
}
public byte getTemperaturaGiornalieraMax() {
return TemperaturaGiornalieraMax;
}
public void setTemperaturaGiornalieraMax(byte temperaturaGiornalieraMax) {
TemperaturaGiornalieraMax = temperaturaGiornalieraMax;
}
public byte getTemperaturaGiornalieraMin() {
return TemperaturaGiornalieraMin;
}
public void setTemperaturaGiornalieraMin(byte temperaturaGiornalieraMin) {
TemperaturaGiornalieraMin = temperaturaGiornalieraMin;
}
public String getPrecipitazioni() {
return precipitazioni;
}
public void setPrecipitazioni(String precipitazioni) {
this.precipitazioni = precipitazioni;
}
public byte getQuantitaprec() {
return quantitaprec;
}
public void setQuantitaprec(byte quantitaprec) {
this.quantitaprec = quantitaprec;
}
public String getTempo() {
return tempo;
}
public void setTempo(String tempo) {
this.tempo = tempo;
}
public byte getUmiditaMax() {
return umiditaMax;
}
public void setUmiditaMax(byte umiditaMax) {
this.umiditaMax = umiditaMax;
}
public byte getUmiditaMin() {
return umiditaMin;
}
public void setUmiditaMin(byte umiditaMin) {
this.umiditaMin = umiditaMin;
}
public short getVelocitaVentoMax() {
return velocitaVentoMax;
}
public void setVelocitaVentoMax(short velocitaVentoMax) {
this.velocitaVentoMax = velocitaVentoMax;
}
public short getVelocitaVentoMin() {
return velocitaVentoMin;
}
public void setVelocitaVentoMin(short velocitaVentoMin) {
this.velocitaVentoMin = velocitaVentoMin;
}
}
Repository
@Repository("TemperatureRepository")
public interface TemperatureRepository extends JpaRepository<InfoMeteo, Long> {
}
Service
public interface TemperatureService {
void saveIndicatoriMeteo(InfoMeteo indicatoreMeteo);
List<InfoMeteo> getAll();
}
Service implementation
@Service("TemperatureService")
public class TemperatureServiceImpl implements TemperatureService {
@Autowired
private TemperatureRepository temperatureRepository; // inietto per dipendenza il
service del repository
@Override
public void saveIndicatoriMeteo(InfoMeteo indicatoreMeteo) {
temperatureRepository.save(indicatoreMeteo);
}
@Override
public List<InfoMeteo> getAll() {
return temperatureRepository.findAll();
}
}
Home.html
<!DOCTYPE html>
<html xmlns:th="http://thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Home Page</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js">
</head>
<body>
<div class="container">
<div class="pb-3 mt-4 mb-2">
<div class = "btn btn-primary" >
</div>
<h2>Gestione Meteo - <small>Lista Indicatori Meteo</small></h2>
</div>
</div>
<div class="col-md-5" style="margin-top:50px;margin-bottom:50px;">
<form method="post" th:action="@{/}" th:object = "${indicatoreMeteo}">
<div class="form-group">
<label for= "data">Data</label>
<input type="text" " field="*{Data}" id="data>
class="form-control" required>
</div>
<div class="form-group">
<label for= "TemperaturaMax">Temperatura Max</label>
<input type="text" field="*{TemperaturaGiornalieraMax}" id="TemperaturaMax"
class="form-control" required>
</div>
<div class="form-group">
<label for= "TemperaturaMin">Temperatura Min</label>
<input type="text" id="TemperaturaMin"
field="*{TemperaturaGiornalieraMin}"
class="form-control" required>
</div>
<div class="form-group">
<label for= "precipitazioni">Precipitazioni (prp)</label>
<input type="text" id="precipitazioni"
field="*{precipitazioni}"
class="form-control" required>
</div>
<div class="form-group">
<label for= "Quantità">Quantità precipitazioni</label>
<input type="text" id="Quantità"
field="*{quantitaprec}"
class="form-control" required>
</div>
<div class="form-group">
<label for= "Tempo">Condizioni meteo</label>
<input type="text" id="Tempo"
field="*{tempo}"
class="form-control" required>
</div>
<div class="form-group">
<label for= "URMax">Ur max (Umidità)</label>
<input type="text" id="URMax"
field="*{umiditaMax}"
class="form-control" required>
</div>
<div class="form-group">
<label for= "URMin">Ur Min (Umidità)</label>
<input type="text" id="URMin"
field="*{umiditaMin}"
class="form-control" required>
</div>
<div class="form-group">
<label for= "WSPDMax">Velocità vento Min (Wv)</label>
<input type="text" id="WSPDMax"
field="*{velocitaVentoMax}"
class="form-control" required>
</div>
<div class="form-group">
<label for= "WSPDMin">Velocità vento Max(Wv)</label>
<input type="text" id="WSPDMin"
field="*{velocitaVentoMin}"
class="form-control" required>
</div>
<button style="margin-top:50px;" type="submit"
class="btn btn-dark"> Salva indicatori Meteo</button>
</form>
</div>
<table class="table table-striped">
<div table= "pb-2 mt-4 mb-3">
<thead>
<tr>
<th scope="col">Data</th>
<th scope="col">Temperatura Max giornaliera</th>
<th scope="col">Temperatura Min giornaliera</th>
<th scope="col">precipitazioni</th>
<th scope="col">Tipo di precipitazioni</th>
<th scope="col">Quantita prec </th>
<th scope="col">Condizioni meteo</th>
<th scope="col">Umidita Max</th>
<th scope="col">Umidita Min</th>
<th scope="col">Velocita Vento Max</th>
<th scope="col">Velocita Vento Min</th>
</tr>
<tbody>
<tr th:each="indicatoreMeteo: ${listaIndicatoriMeteo}">
<td th:text= "${indicatoreMeteo.Data}"></td>
<td th:text= "${indicatoreMeteo.TemperaturaGiornalieraMax}"></td>
<td th:text= "${indicatoreMeteo.TemperaturaGiornalieraMin}"></td>
<td th:text= "${indicatoreMeteo.precipitazioni}"></td>
<td th:text= "${indicatoreMeteo.quantitaprec}"></td>
<td th:text= "${indicatoreMeteo.tempo}"></td>
<td th:text= "${indicatoreMeteo.umiditaMax}"></td>
<td th:text= "${indicatoreMeteo.umiditaMin}"></td>
<td th:text= "${indicatoreMeteo.velocitaVentoMax}"></td>
<td th:text= "${indicatoreMeteo.velocitaVentoMin}"></td>
</tbody>
</table>
I have tried different solutions but it keeps giving me this kind of exception all the time, I don't know what to do