Home > Enterprise >  SpringBoot microservice InvalidDefinitionException
SpringBoot microservice InvalidDefinitionException

Time:10-01

I developed a microservice and when I go to get to postman ( http://localhost:8080/user/utenti/ ) I get this error InvalidDefinitionException No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor and no properties discovered create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0]->com.application.dto.UserDto["applicationRoleID"]->com.poste.anagrafica.entity.Role$HibernateProxy$N0iZZA2I["hibernateLazyInitializer"])

Can you help me please? For clarity I enclose the schema of the database and the classes entity , dto and controller

enter image description here

The Entity classes

"""

@Entity
@Table(name = "USERS")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class User implements Serializable {
@Id
@Column(name = "user_id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "created_date")
private LocalDateTime createdDate;

@Column(name = "deleted", nullable = false)
private Long number;

@Column(name = "modified_date")
private LocalDateTime modifiedDate;

@Column(name = "birth_place")
private String birthPlace;

@Column(name = "birthday")
private Date birthDay;

@Column(name = "canNominate")
private Long canNominate;

@Column(name = "email")
private String email;

@Column(name = "firstName")
private String firstName;

@Column(name= "fiscalCode")
private String fiscalCode;

@Column(name = "hiringDate")
private Date hiringDate;

@Column(name ="last_name")
private String lastName;

@Column(name = "matricola")
private String matricola;

@Column(name = "position")
private String position;

@Column(name = "registration_number")
private String registrationNumber;

@Column(name = "replaced")
private Long replaced;

@Column(name = "terminationDate")
private Date terminationDate;

@Column(name = "user_status")
private String userStatus;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application_role_id")
private Role applicationRoleID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "company_id")
private Company companyID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "direction_id")
private Direction directions ;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "level_id")
private Levels levelID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "referent_id")
private User referentID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id")
private Role roleID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "task_id")
private EmployeeTask taskID;

} """

the UserDTO class

"""

@Data
public class UserDto {


private Long userId;


private LocalDateTime createdDate;

private Long number;

private LocalDateTime modifiedDate;


private String birthPlace;


private Date birthDay;


private Long canNominate;


private String email;

private String firstName;


private String fiscalCode;


private Date hiringDate;

private String lastName;


private String matricola;


private String position;

private String registrationNumber;


private Long replaced;


private Date terminationDate;


private String userStatus;


private Role applicationRoleID;


private Company companyID;


private Direction directions ;



private Levels levelID;

private User referentID;


private Role role;

private EmployeeTask taskID;

}

"""

the controller class """

 @RestController
 @RequestMapping("/user")
 @Log
 public class UserController {

private static final Logger logger = LoggerFactory.getLogger(UserController.class);

@Autowired
UserService userService;

@GetMapping(value = "/cerca/{registration_number}", produces = "application/json")
public ResponseEntity<List<UserDto>> listUserByRegistrationNumber(@PathVariable("registration_number") String registrationNumber)
        throws ChangeSetPersister.NotFoundException
{
    log.info("****** Ottengo l'user con numeroRegistrazione "   registrationNumber   " *******");

    List<UserDto> user = userService.SelByRegistrationNumber(registrationNumber);



    return new ResponseEntity<List<UserDto>>(user, HttpStatus.OK);
}

@GetMapping(value = "/utenti", produces = "application/json")
public ResponseEntity<List<UserDto>> listAllUsers ()throws ChangeSetPersister.NotFoundException{


    List<UserDto> user = userService.SelTutti();



    return new ResponseEntity<List<UserDto>>(user, HttpStatus.OK);


}
}

"""

the application.properties

"""

spring.datasource.url = jdbc:oracle:thin:@192.134.2.82:1521/orcl

spring.datasource.username =admin
spring.datasource.password =zzzx
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver



# JPA settings
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
spring.jpa.hibernate.use-new-id-generator-mappings=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.implicit-       strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

"""

CodePudding user response:

You can try

spring.jackson.serialization.fail-on-empty-beans=false

in your application.properties.

  • Related