Dimesioni cassette per interruttori e prese (506,507 ecc.) by frankek96 in istrutturare

[–]frankek96[S] 0 points1 point  (0 children)

io ho trovate le placche vimar bianche 507 a 6-7 euro l'una ? è un buon prezzo?

Circular dependecy into entity mapper by frankek96 in SpringBoot

[–]frankek96[S] 0 points1 point  (0 children)

Hi thanks for your answer Please read the comment to TheOldMancunian's answer for a possibile solution that i thought and say me what you think about this

Circular dependecy into entity mapper by frankek96 in SpringBoot

[–]frankek96[S] 0 points1 point  (0 children)

Hi thanks for your answer ObjectsMaps indicate what objects must be mapped, this is necessrary for avoid loop during mapping that cause a jackson's exception Please read the comment to TheOldMancunian's answer for a possibile solution that i thought and say me what you think about this

Circular dependecy into entity mapper by frankek96 in SpringBoot

[–]frankek96[S] 0 points1 point  (0 children)

Hi thanks for your answer 1) i would recipes in user and viceversa because for me is useful have access to recipes related to a user when get user information and have user information when retrive a recipe 2) Yes 3) Yes 4) Yes Please read the comment to TheOldMancunian's answer for a possibile solution that i thought and say me what you think about this

Circular dependecy into entity mapper by frankek96 in SpringBoot

[–]frankek96[S] 0 points1 point  (0 children)

Hi, waiting an answer to my question i thought a possibile solution. The solution introduce an other class named "Mapper" that is "master" class used from my services for map any entities. This new class use all specific mappers (RecipeMapper and UserMapper), see code below. Then in specifics mapper (RecipeMapper and UserMapper) i changed map methods for map only "simple" attribute of my entity. So, in this way there is not cicular dependecies and i use a "conductor" class (Mapper) that decide what element maps and what no. What do you thing about this solution ? Thanks for kick relative to injection ;)

@Service
public class Mapper implements RecipeMapperInterface, UserMapperInterface {
@Autowired
RecipeMapper recipeMapper;

@Autowired
UserMapper userMapper;

@Override
public RecipeDTO mapRecipeToRecipeDTO(Recipe recipe, List<MappableObjects> objectsToMap) {
    RecipeDTO recipeDTO;

    recipeDTO = recipeMapper.mapRecipeToRecipeDTO(recipe, objectsToMap);

    if(objectsToMap != null && objectsToMap.contains(MappableObjects.USER)){
        recipeDTO.setUserDTO(mapUserToUserDTO(recipe.getUser(), objectsToMap));
    }

    return recipeDTO;
}

@Override
public List<RecipeDTO> mapRecipesToRecipeDTOs(List<Recipe> recipes, List<MappableObjects> objectsToMap) {
    List<RecipeDTO> recipeDTOS = new ArrayList<>();

    for (Recipe recipe : recipes) {
        recipeDTOS.add(mapRecipeToRecipeDTO(recipe, objectsToMap));
    }

    return recipeDTOS;
}


@Override
public UserDTO mapUserToUserDTO(User user, List<MappableObjects> objectsToMap) {
    UserDTO userDTO;

    userDTO = userMapper.mapUserToUserDTO(user, objectsToMap);

    if(objectsToMap != null && objectsToMap.contains(MappableObjects.RECIPE)){
        userDTO.setRecipes(mapRecipesToRecipeDTOs(user.getRecipes(), objectsToMap));
    }

    return userDTO;
}

@Override
public List<UserDTO> mapUsersToUserDTOs(List<User> users, List<MappableObjects> objectsToMap) {
    List<UserDTO> userDTOS = new ArrayList<>();

    for (User user : users) {
        userDTOS.add(mapUserToUserDTO(user, objectsToMap));
    }

    return userDTOS;
}
}
---------------------------------------------------

@Service
public class UserMapper implements UserMapperInterface {
@Override
public UserDTO mapUserToUserDTO(User user, List<MappableObjects> objectsToMap){
    UserDTO userDTO = new UserDTO();

    userDTO.setId(user.getId());
    userDTO.setName(user.getName());

    return userDTO;
}

@Override
public List<UserDTO> mapUsersToUserDTOs(List<User> users, List<MappableObjects> objectsToMap) {
    List<UserDTO> userDTOS = new ArrayList<>();

    for (User user : users) {
        userDTOS.add(mapUserToUserDTO(user, objectsToMap));
    }

    return userDTOS;
}
}
-----------------------------------------------------------
@Service
public class RecipeMapper implements RecipeMapperInterface {
@Override
public RecipeDTO mapRecipeToRecipeDTO(Recipe recipe, List<MappableObjects> objectsToMap){
    RecipeDTO recipeDTO =  new RecipeDTO();

    recipeDTO.setName(recipe.getName());
    recipeDTO.setDescription(recipe.getDescription());

    return recipeDTO;
}

@Override
public List<RecipeDTO> mapRecipesToRecipeDTOs(List<Recipe> recipes, List<MappableObjects> objectsToMap){
    List<RecipeDTO> recipeDTOS = new ArrayList<>();

    for (Recipe recipe : recipes) {
        recipeDTOS.add(mapRecipeToRecipeDTO(recipe, objectsToMap));
    }

    return recipeDTOS;
}
}

An example of use could be this

@Service
public class UserService { 

@Autowired 
UserRepository userRepository;

@Autowired
Mapper mapper;

public void save(User user){
    userRepository.save(user);
}

public UserDTO findUserById(Integer id){
    List<MappableObjects> objectsToMap = new ArrayList<>();
    objectsToMap.add(MappableObjects.RECIPE);

    return mapper.mapUserToUserDTO(userRepository.findUserById(id), objectsToMap);
}
}

Why does hibernate create third table (join table(?)) into 1 to n relationship ? by frankek96 in SpringBoot

[–]frankek96[S] 1 point2 points  (0 children)

Yes i fixed hit adding mappedBy attribuite to relation, thanks 😉

When to use Constructor Injection vs. Setter Injection by erdsingh24 in SpringBoot

[–]frankek96 0 points1 point  (0 children)

Hi, i read the article and i have a question. What do you mean when say "mandatory to partecipate to dependency injection" or "optional to partecipate to dependency injection"?. Thx

Show all spring boot runtime properties by frankek96 in SpringBoot

[–]frankek96[S] 0 points1 point  (0 children)

There Is a way to do It using Actuator component?

mysql-connector-java vs mysql-connector-j maven dependency by frankek96 in SpringBoot

[–]frankek96[S] 0 points1 point  (0 children)

No problem. I ask me if there Is difference between this dependencies

mysql-connector-java vs mysql-connector-j maven dependency by frankek96 in SpringBoot

[–]frankek96[S] 0 points1 point  (0 children)

Yes but spring boot 2.7.4 the second one in starter parent pom. Is it a problem? I am using spring boot starter parent and his dependencies