убрал FetchType.EAGER game, остался order
This commit is contained in:
parent
e7f8b1ffca
commit
d9dc12f427
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -1,58 +0,0 @@
|
||||
2024-04-15 11:25:18.220809+04:00 database: wrong user or password; user: "SA"
|
||||
org.h2.message.DbException: Неверное имя пользователя или пароль
|
||||
Wrong user name or password [28000-224]
|
||||
at org.h2.message.DbException.get(DbException.java:223)
|
||||
at org.h2.message.DbException.get(DbException.java:199)
|
||||
at org.h2.message.DbException.get(DbException.java:188)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:154)
|
||||
at org.h2.engine.Engine.openSession(Engine.java:222)
|
||||
at org.h2.engine.Engine.createSession(Engine.java:201)
|
||||
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:343)
|
||||
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:125)
|
||||
at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:288)
|
||||
at org.h2.server.web.WebServer.getConnection(WebServer.java:811)
|
||||
at org.h2.server.web.WebApp.login(WebApp.java:1039)
|
||||
at org.h2.server.web.WebApp.process(WebApp.java:227)
|
||||
at org.h2.server.web.WebApp.processRequest(WebApp.java:177)
|
||||
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
|
||||
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
|
||||
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
|
||||
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
|
||||
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
|
||||
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
|
||||
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
|
||||
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
|
||||
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
|
||||
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
|
||||
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
|
||||
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
|
||||
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
|
||||
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
|
||||
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
|
||||
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
|
||||
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
|
||||
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
|
||||
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
|
||||
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391)
|
||||
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
|
||||
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
|
||||
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744)
|
||||
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
|
||||
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
|
||||
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
|
||||
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
|
||||
at java.base/java.lang.Thread.run(Thread.java:1623)
|
||||
Caused by: org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Неверное имя пользователя или пароль
|
||||
Wrong user name or password [28000-224]
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:522)
|
||||
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
|
||||
... 50 more
|
@ -61,15 +61,15 @@ public class DemoApplication implements CommandLineRunner {
|
||||
genres2.add(genre2);
|
||||
|
||||
final var game1 = gameService.create(new GameEntity(type1,"Game1",2100.0,"good game", genres1));
|
||||
// final var game2 = gameService.create(new GameEntity( type2, "Game2", 1200.0,"bad game", genres1));
|
||||
final var game2 = gameService.create(new GameEntity( type2, "Game2", 1200.0,"bad game", genres2));
|
||||
final List<GameEntity> games = new ArrayList<GameEntity>();
|
||||
games.add(game1);
|
||||
// games.add(game2);
|
||||
games.add(game2);
|
||||
|
||||
var user1 = userService.create(new UserEntity( "login1", "email@mail.com", "qwerty123"));
|
||||
// var user2 = userService.create(new UserEntity( "login2", "email@gmail.com", "qwerty1234"));
|
||||
|
||||
orderService.create(6, new OrderEntity(user1,games));
|
||||
orderService.create(7, new OrderEntity(user1,games));
|
||||
// orderService.create(1, new OrderEntity(user1,games));
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,8 @@ import com.example.demo.types.model.TypeEntity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@ -25,7 +24,7 @@ public class GameEntity extends BaseEntity{
|
||||
private Double price;
|
||||
@Column(nullable = false)
|
||||
private String description;
|
||||
@OneToMany(fetch=FetchType.EAGER)
|
||||
@ManyToMany()
|
||||
@Column(unique = false)
|
||||
private final List<GenreEntity> genres = new ArrayList<>();
|
||||
@OneToOne
|
||||
|
@ -4,6 +4,7 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
@ -14,5 +15,32 @@ public interface GameRepository extends CrudRepository<GameEntity, Long>, Paging
|
||||
Optional<GameEntity> findOneById(long id);
|
||||
Page<GameEntity> findByTypeIdAndGenres(long typeId, GenreEntity genre, Pageable pageable);
|
||||
Page<GameEntity> findByTypeId(long typeId, Pageable pageable);
|
||||
Page<GameEntity> findByGenres(GenreEntity genre, Pageable pageable);
|
||||
//Page<GameEntity> findByGenres(GenreEntity genre, Pageable pageable);
|
||||
|
||||
@Query("select distinct g from GameEntity g join fetch g.genres ge where ge.id = ?1")
|
||||
Page<GameEntity> findByGenres(long genre, Pageable pageable);
|
||||
}
|
||||
|
||||
/* "select "
|
||||
+ "ga.id, ga.description, ga.name, ga.price, ga.type_id "
|
||||
+ "from games ga left join fetch games_genres g on ga.id = g.game_entity_id "
|
||||
+ "where g.id = ?1 "
|
||||
+ "order by ga.id"*/
|
||||
|
||||
//select ge1_0.id,ge1_0.name from genres ge1_0 where ge1_0.id=?
|
||||
|
||||
//select ge1_0.id,ge1_0.description,ge1_0.name,ge1_0.price,ge1_0.type_id
|
||||
//from games ge1_0 left join games_genres g1_0 on ge1_0.id=g1_0.game_entity_id
|
||||
//where g1_0.genres_id=? offset ? rows fetch first ? rows only
|
||||
|
||||
//select te1_0.id,te1_0.name from types te1_0 where te1_0.id=?
|
||||
|
||||
//select g1_0.game_entity_id,g1_1.id,g1_1.name from games_genres g1_0 join genres g1_1 on g1_1.id=g1_0.genres_id where g1_0.game_entity_id=?
|
||||
|
||||
// @Query("select "
|
||||
// + "t as type, "
|
||||
// + "coalesce(sum(o.price), 0) as totalPrice, "
|
||||
// + "coalesce(sum(o.count), 0) as totalCount "
|
||||
// + "from TypeEntity t left join OrderEntity o on o.type = t and o.user.id = ?1 "
|
||||
// + "group by t order by t.id")
|
||||
// List<OrderGrouped> getOrdersTotalByType(long userId);
|
||||
|
@ -53,7 +53,7 @@ public class GameService {
|
||||
return repository.findByTypeIdAndGenres(typeId, NeedGenre, pageRequest);
|
||||
}
|
||||
if(Objects.equals(typeId, 0L) && !Objects.equals(genre, 0L)){
|
||||
return repository.findByGenres(NeedGenre, pageRequest);
|
||||
return repository.findByGenres(genre, pageRequest);
|
||||
}
|
||||
if(!Objects.equals(typeId, 0L) && Objects.equals(genre, 0L)){
|
||||
return repository.findByTypeId(typeId, pageRequest);
|
||||
|
@ -25,7 +25,7 @@ public class OrderEntity extends BaseEntity{
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "userId", nullable = false)
|
||||
private UserEntity user;
|
||||
@OneToMany(fetch=FetchType.EAGER)
|
||||
@OneToMany(fetch=FetchType.EAGER) //cделать запрос jpa
|
||||
private Set<GameEntity> games = new HashSet<>();
|
||||
|
||||
public OrderEntity(){
|
||||
|
76
src/test/java/com/example/demo/TypeServiceTests.java
Normal file
76
src/test/java/com/example/demo/TypeServiceTests.java
Normal file
@ -0,0 +1,76 @@
|
||||
// package com.example.demo;
|
||||
|
||||
// import org.junit.jupiter.api.AfterEach;
|
||||
// import org.junit.jupiter.api.Assertions;
|
||||
// import org.junit.jupiter.api.BeforeEach;
|
||||
// import org.junit.jupiter.api.Order;
|
||||
// import org.junit.jupiter.api.Test;
|
||||
// import org.junit.jupiter.api.TestMethodOrder;
|
||||
// import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
// import org.springframework.beans.factory.annotation.Autowired;
|
||||
// import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
// import com.example.demo.core.error.NotFoundException;
|
||||
// import com.example.demo.types.model.TypeEntity;
|
||||
// import com.example.demo.types.service.TypeService;
|
||||
|
||||
// @SpringBootTest
|
||||
// @TestMethodOrder(OrderAnnotation.class)
|
||||
// class TypeServiceTests {
|
||||
// @Autowired
|
||||
// private TypeService typeService;
|
||||
|
||||
// private TypeEntity type;
|
||||
|
||||
// @BeforeEach
|
||||
// void createData() {
|
||||
// removeData();
|
||||
|
||||
// type = typeService.create(new TypeEntity("Ноутбук"));
|
||||
// typeService.create(new TypeEntity("Телефон"));
|
||||
// typeService.create(new TypeEntity("Игровая приставка"));
|
||||
// }
|
||||
|
||||
// @AfterEach
|
||||
// void removeData() {
|
||||
// typeService.getAll().forEach(item -> typeService.delete(item.getId()));
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// void getTest(){
|
||||
// Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L));
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// @Order(1)
|
||||
// void createTest(){
|
||||
// typeService.create(new TypeEntity("Игра"));
|
||||
// typeService.create(new TypeEntity("Программа"));
|
||||
// final TypeEntity last = typeService.create(new TypeEntity("Игра2"));
|
||||
// Assertions.assertEquals(5, typeService.getAll().size());
|
||||
// Assertions.assertEquals(last, typeService.get(10L));
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// @Order(2)
|
||||
// void updateTest(){
|
||||
// final String test = "TEST";
|
||||
// final TypeEntity newEntity = typeService.update(9L, new TypeEntity(test));
|
||||
// Assertions.assertEquals(5, typeService.getAll().size());
|
||||
// Assertions.assertEquals(newEntity, typeService.get(9L));
|
||||
// Assertions.assertEquals(test, newEntity.getName());
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// @Order(3)
|
||||
// void deleteTest(){
|
||||
// typeService.delete(9L);
|
||||
// Assertions.assertEquals(8, typeService.getAll().size());
|
||||
// final TypeEntity last = typeService.get(8L);
|
||||
// Assertions.assertEquals(8L, last.getId());
|
||||
|
||||
// final TypeEntity newEntity = typeService.create(new TypeEntity("Игра"));
|
||||
// Assertions.assertEquals(9, typeService.getAll().size());
|
||||
// Assertions.assertEquals(11L, newEntity.getId());
|
||||
// }
|
||||
// }
|
Loading…
x
Reference in New Issue
Block a user