8

I'm new with JPA / Hibernate with Spring Boot and I've been facing the same error for over 6hours now, this is driving me crazy.

Basically, it all start at my Controller here

@RestController
@RequestMapping("patientApi")
public class RestPatientController {

    public static final Logger LOGGER = LoggerFactory.getLogger(RestPatientController.class);

    @Autowired
    private PatientService patientService;

    [...]

    @RequestMapping(value = "/patient/prises_en_charge/{id}", method = RequestMethod.GET)
    public ResponseEntity<List<PriseEnCharge>> listAllPrisesEnChargeByPatient(@PathVariable("id") long id) {

        Patient currentPatient = patientService.findById(id);
        LOGGER.info("Récupération de toutes les prises en charges d'un patient avec id {}", currentPatient);
        List<PriseEnCharge> prisesEnCharge = patientService.findAllPrisesEnChargeByPatient(currentPatient);
        LOGGER.info("Liste de prises en charge {} ({} elements)", prisesEnCharge, prisesEnCharge.size());
        if (prisesEnCharge.isEmpty()) {
            LOGGER.debug("La liste des prises en charge est vide");
            return new ResponseEntity(HttpStatus.NO_CONTENT);
            // You many decide to return HttpStatus.NOT_FOUND

        }
        return new ResponseEntity<List<PriseEnCharge>>(prisesEnCharge, HttpStatus.OK);
    }

}

where I catch the ID of the element I want more data for. I then call the DAO within my service

@Service("patientService")
@Transactional
public class PatientServiceImpl implements PatientService {

    @Autowired
    private PriseEnChargeDao priseEnChargeDao;

    [...]

    @Override
    public List<PriseEnCharge> findAllPrisesEnChargeByPatient(Patient patient) {
        return priseEnChargeDao.findPriseEnChargeByPatient(patient);
    }

}

DAO being

@Repository
public interface PriseEnChargeDao extends JpaRepository<PriseEnCharge, Long> {

    @Query("from PriseEnCharge where id_patient = :patient")
    public List<PriseEnCharge> findPriseEnChargeByPatient(@Param("patient") Patient patient);

}

No matter what I tried It keeps throwing exception "java.io.StreamCorruptedException: invalid stream header: 32303138". I honnestly don't know anymore, I'm kinda despaired on that case.

2
  • This issue is happening when some properties of domain entities cannot be deserialized. Can you paste your domain class
    – Yogi
    Commented Apr 17, 2018 at 12:52
  • I'm not sure what my domain class is. I've just joined the project and it is not me who configured it all, they just told me to go do that.
    – Kpo
    Commented Apr 17, 2018 at 13:03

2 Answers 2

13

I am going to make a guess here. If you interpret 32303138 as a 32 bit word in hexadecimal and "decode" it as ASCII characters, you get "2018". That looks to me like the first 4 characters of a date string of some kind.

My guess is that something is attempting to deserialize a character string as if it was an object stream. That implies that there is a mismatch between the database schema and the hibernate mappings.

11
  • My date is stored as a serializable LocalDate object in my model, and as a timestamp without time zone in my table.
    – Kpo
    Commented Apr 17, 2018 at 13:05
  • Actually, the evidence suggests that it is probably a VARCHAR in the database! And that the VARCHAR contains a formatted date / time string. Either way, the hibernate mapping is incorrectly attempting to deserialize some data that wasn't created by serialization.
    – Stephen C
    Commented Apr 17, 2018 at 13:07
  • Could it be because I filled the row manually? We don't have an UI yet to fill a form so they told me to manually insert datas in the table to do my tests.
    – Kpo
    Commented Apr 17, 2018 at 13:13
  • That is plausible. But IMO the real problem is in the mapping. Storing dates in the database as serialized Java objects is a bad idea.
    – Stephen C
    Commented Apr 17, 2018 at 14:30
  • In which form should we store them then?
    – Kpo
    Commented Apr 17, 2018 at 15:04
0

Came across this (same error different value) in Spring 3 + Hibernate 6. Turned out that I was missing @Embeddable on the custom ID I had defined for the entity. It's a technically correct error message, but not very helpful when it feels more like an attribute problem.

Hope this helps others trying to track down this issue.

Not the answer you're looking for? Browse other questions tagged or ask your own question.