Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 堆栈溢出错误的解决方案_Java_Spring_Spring Boot_Spring Data Jpa - Fatal编程技术网

Java 堆栈溢出错误的解决方案

Java 堆栈溢出错误的解决方案,java,spring,spring-boot,spring-data-jpa,Java,Spring,Spring Boot,Spring Data Jpa,要使用地址表中的城市进行搜索 实体:酒店 @JsonManagedReference @OneToMany(cascade = CascadeType.ALL, mappedBy = "hotel") private List<Address> address; 控制器: @GetMapping("/forSearch") public String searchHotelPage(Model model, Address address){

要使用地址表中的城市进行搜索

实体:酒店

@JsonManagedReference
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "hotel")
    private List<Address> address;
控制器:

@GetMapping("/forSearch")
    public String searchHotelPage(Model model, Address address){
        model.addAttribute("address", address);
        return "search-hotel";
    }

    @GetMapping("/search-hotel-city/{city}")
    public String searchHotel(@RequestParam("city") String city, Model model){
        List<Address> addresses = addressService.searchAddressByCity(city);
        System.out.println("this is address: "+ addresses);
        model.addAttribute("address",addresses );
        return "search-hotel";
    }
服务:

public List<Address> searchAddressByCity(String city) {
        return addressRepository.findAll();
    }
搜索和列表视图:

<form th:action="@{/search-hotel-city/city?city=${address.city}}" method="get">
            <div class="form-group mb-2">
                <input type="text" class="form-control" name="city" id="city" placeholder="Search "/>
                <input type="submit" value="search" class="btn btn-primary">   
            </div>
        </form>

        <hr/>

        <table class="table">
            <thead>
            <tr>
                <th scope="col">Id</th>
                <th scope="col">roadNumber</th>
                <th scope="col">city</th>
                <th scope="col">country</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="address: ${addresses}">
                <th scope="row" th:text="${address.id}"></th>
                <td th:text="${address.roadNumber}"></td>
                <td th:text="${address.city}"></td>
                <td th:text="${address.country}"></td>
            </tr>

            </tbody>
        </table>
错误:

Hibernate: select address0_.hotel_id as hotel_id5_0_0_, address0_.id as id1_0_0_, address0_.id as id1_0_1_, address0_.city as city2_0_1_, address0_.country as country3_0_1_, address0_.hotel_id as hotel_id5_0_1_, address0_.road_number as road_num4_0_1_ from address address0_ where address0_.hotel_id=?
2019-07-28 12:58:28.184 ERROR 9836 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause

java.lang.StackOverflowError: null
    at java.lang.Exception.<init>(Exception.java:102) ~[na:1.8.0_212]
    at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:89) ~[na:1.8.0_212]
我想搜索这个城市。但当我发现有错误发生时。我试过了,但没能解决这个问题。请帮帮我。谢谢

删除System.out.println这是地址:+地址;从searchHotel。 它可能导致无限次调用,从而导致StackOverflower错误

可能的原因:

大多数列表实现的toString方法都会遍历列表元素并对其调用toString。 使用Lombok和您的automatics,生成的哈希代码被集合使用,因此运行无限调用 删除System.out.println这是地址:+地址;从searchHotel来,告诉我
Hibernate: select address0_.hotel_id as hotel_id5_0_0_, address0_.id as id1_0_0_, address0_.id as id1_0_1_, address0_.city as city2_0_1_, address0_.country as country3_0_1_, address0_.hotel_id as hotel_id5_0_1_, address0_.road_number as road_num4_0_1_ from address address0_ where address0_.hotel_id=?
2019-07-28 12:58:28.184 ERROR 9836 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause

java.lang.StackOverflowError: null
    at java.lang.Exception.<init>(Exception.java:102) ~[na:1.8.0_212]
    at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:89) ~[na:1.8.0_212]