Убрал fetch order
This commit is contained in:
parent
d9dc12f427
commit
fd9982fdcb
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -67,9 +67,9 @@ public class DemoApplication implements CommandLineRunner {
|
|||||||
games.add(game2);
|
games.add(game2);
|
||||||
|
|
||||||
var user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123"));
|
var user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123"));
|
||||||
// var user2 = userService.create(new UserEntity( "login2", "email@gmail.com", "qwerty1234"));
|
var user2 = userService.create(new UserEntity( "login2", "email@gmail.com", "qwerty1234"));
|
||||||
|
|
||||||
orderService.create(7, new OrderEntity(user1,games));
|
orderService.create(7, new OrderEntity(user1,games));
|
||||||
// orderService.create(1, new OrderEntity(user1,games));
|
orderService.create(8, new OrderEntity(user2,games));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,9 @@ import com.example.demo.games.model.GameEntity;
|
|||||||
import com.example.demo.users.model.UserEntity;
|
import com.example.demo.users.model.UserEntity;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToMany;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import jakarta.persistence.OneToMany;
|
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -25,7 +24,7 @@ public class OrderEntity extends BaseEntity{
|
|||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "userId", nullable = false)
|
@JoinColumn(name = "userId", nullable = false)
|
||||||
private UserEntity user;
|
private UserEntity user;
|
||||||
@OneToMany(fetch=FetchType.EAGER) //cделать запрос jpa
|
@ManyToMany() //cделать запрос jpa
|
||||||
private Set<GameEntity> games = new HashSet<>();
|
private Set<GameEntity> games = new HashSet<>();
|
||||||
|
|
||||||
public OrderEntity(){
|
public OrderEntity(){
|
||||||
|
@ -5,7 +5,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
|
|
||||||
@ -16,6 +16,7 @@ public interface OrderRepository extends CrudRepository<OrderEntity, Long>, Pagi
|
|||||||
|
|
||||||
List<OrderEntity> findByUserId(long userId);
|
List<OrderEntity> findByUserId(long userId);
|
||||||
|
|
||||||
|
@Query("select o from OrderEntity o join fetch o.games where o.user.id = ?1")
|
||||||
Page<OrderEntity> findByUserId(long userId, Pageable pageable);
|
Page<OrderEntity> findByUserId(long userId, Pageable pageable);
|
||||||
|
|
||||||
//Можно сделать запрос на сумму JPQL
|
//Можно сделать запрос на сумму JPQL
|
||||||
|
@ -6,8 +6,6 @@ import org.springframework.data.domain.Pageable;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.example.demo.core.error.NotFoundException;
|
import com.example.demo.core.error.NotFoundException;
|
||||||
import com.example.demo.orders.model.OrderEntity;
|
import com.example.demo.orders.model.OrderEntity;
|
||||||
import com.example.demo.orders.repository.OrderRepository;
|
import com.example.demo.orders.repository.OrderRepository;
|
||||||
@ -24,11 +22,6 @@ public class OrderService {
|
|||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<OrderEntity> getAll(long userId){
|
|
||||||
userService.get(userId);
|
|
||||||
return repository.findByUserId(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Page<OrderEntity> getAll(long userId, int page, int size){
|
public Page<OrderEntity> getAll(long userId, int page, int size){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user