I have one problem. I was developing application on Spring Boot using MySQL, i have a Get-method:
@Entity
@Table(name = "users", uniqueConstraints = {
@UniqueConstraint(columnNames = "email")
})
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Builder
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
private String phone;
private String password;
@ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
@CollectionTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"))
@Enumerated(EnumType.STRING)
private Set<Role> roles;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(
name = "user_dish",
joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "dish_id", referencedColumnName = "id")
)
private Set<DishEntity> cart;
}
@GetMapping("email")
public ResponseEntity<User> getUserByEmail(@RequestParam(value = "email") String email) {
User response = userService.findByEmail(email);
return ResponseEntity.ok(response);
}
@Override
public User findByEmail(String email) {
log.info("Getting user by email: {}", email);
UserEntity userEntity;
try{
userEntity = userRepository.findByEmail(email);
}catch (Exception ex){
throw new OperationFailedException("Getting user by email method failed");
}
return userEntity == null ? null : ModelUtils.buildUser(userEntity);
}
public static User buildUser(UserEntity userEntity) {
Set<Dish> cart = buildUserCart(userEntity);
return User.builder()
.id(userEntity.getId())
.name(userEntity.getName())
.email(userEntity.getEmail())
.phone(userEntity.getPhone())
.password(userEntity.getPassword())
.roles(userEntity.getRoles())
.cart(cart)
.build();
}
private static Set<Dish> buildUserCart(UserEntity userEntity) {
Set<Dish> cart = new HashSet<>();
userEntity.getCart().forEach(dishEntity -> {
Dish dish = buildDish(dishEntity);
cart.add(dish);
});
return cart;
}
public static Dish buildDish(DishEntity dishEntity) {
return Dish.builder()
.id(dishEntity.getId())
.image(Base64.encodeBase64String(dishEntity.getImage()) != null
? "data:image/png;base64," + Base64.encodeBase64String(dishEntity.getImage())
: Base64.encodeBase64String(dishEntity.getImage()))
.price(dishEntity.getPrice())
.title(dishEntity.getTitle())
.description(dishEntity.getDescription())
.category(dishEntity.getCategory())
.count(dishEntity.getCount())
.totalPrice(dishEntity.getTotalPrice())
.build();
}
I checked it in postman, it works with MySQL, but when i deployed it to Heroku, i got a problem. If I try to get user by email with empty cart, i get it. But when user's cart contains dish, i get problem. By the way, fild all method works.

But when I was developing my application and used MySQL, I didn't have problems and got user with it's cart. What could happen? Logs in Heroku after this 2 methods:
2022-09-16T08:08:44.179254+00:00 heroku[router]: at=info method=GET path="/users/email?email=ivan@gmail.com" host=internet-market-ma.herokuapp.com request_id=7c8539e9-ee28-4570-a688-26
30e6860aad fwd="31.24.88.124" dyno=web.1 connect=0ms service=23ms status=200 bytes=512 protocol=http
2022-09-16T08:09:09.902656+00:00 heroku[router]: at=info method=GET path="/users/email?email=matvey@gmail.com" host=internet-market-ma.herokuapp.com request_id=e6ee9a97-c87c-48e7-b77c-
3b384ef7c646 fwd="31.24.88.124" dyno=web.1 connect=0ms service=36ms status=417 bytes=581 protocol=http
2022-09-16T08:09:09.867231+00:00 app[web.1]: 2022-09-16 08:09:09.867 INFO 4 --- [io-58944-exec-8] c.e.i.s.implementations.UserServiceImpl : Getting user by email: matvey@gmail.com
2022-09-16T08:09:09.867788+00:00 app[web.1]: Hibernate: select userentity0_.id as id1_4_, userentity0_.email as email2_4_, userentity0_.name as name3_4_, userentity0_.password as passw
ord4_4_, userentity0_.phone as phone5_4_ from users userentity0_ where userentity0_.email=?
2022-09-16T08:09:09.883943+00:00 app[web.1]: Hibernate: select roles0_.user_id as user_id1_3_0_, roles0_.roles as roles2_3_0_ from user_role roles0_ where roles0_.user_id=?
2022-09-16T08:09:09.891309+00:00 app[web.1]: Hibernate: select cart0_.user_id as user_id1_2_0_, cart0_.dish_id as dish_id2_2_0_, dishentity1_.id as id1_0_1_, dishentity1_.category as c
ategory2_0_1_, dishentity1_.count as count3_0_1_, dishentity1_.description as descript4_0_1_, dishentity1_.image as image5_0_1_, dishentity1_.price as price6_0_1_, dishentity1_.title a
s title7_0_1_, dishentity1_.total_price as total_pr8_0_1_ from user_dish cart0_ inner join dishes dishentity1_ on cart0_.dish_id=dishentity1_.id where cart0_.user_id=?
2022-09-16T08:09:09.898279+00:00 app[web.1]: 2022-09-16 08:09:09.898 WARN 4 --- [io-58944-exec-8] o.h.e.loading.internal.LoadContexts : HHH000100: Fail-safe cleanup (collections)
: org.hibernate.engine.loading.internal.CollectionLoadContext@25c29520<rs=HikariProxyResultSet@810256782 wrapping org.postgresql.jdbc.PgResultSet@1aafd682>
2022-09-16T08:09:09.898484+00:00 app[web.1]: 2022-09-16 08:09:09.898 WARN 4 --- [io-58944-exec-8] o.h.e.l.internal.CollectionLoadContext : HHH000160: On CollectionLoadContext#cleanu
p, localLoadingCollectionKeys contained [1] entries
I shared project on github! Here: https://github.com/MatveyAndrosyukk/internet_market_backend.