Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA invalid stream header: 32303138

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.

like image 837
Kpo Avatar asked Apr 17 '18 12:04

Kpo


1 Answers

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.

like image 199
Stephen C Avatar answered Oct 30 '22 00:10

Stephen C