Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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_Hibernate - Fatal编程技术网

Java 为什么此处的预期类型与我的参数不同?我该如何着手修复它呢?

Java 为什么此处的预期类型与我的参数不同?我该如何着手修复它呢?,java,hibernate,Java,Hibernate,//这是咖啡库链接的界面 //以及从 //我需要帮助评估为什么我的代码是错误的给我一个错误的状态 < java.lang.IllegalArgumentException:参数值元素[com.theironyard.Entities]。Coffee@123ec0f1]与预期类型[com.theironyard.Entities.Tag(不适用)]不匹配 package com.theironyard.Repositories; 进口com.theironyard.Entities.Coffee;

//这是咖啡库链接的界面 //以及从 //我需要帮助评估为什么我的代码是错误的给我一个错误的状态 < java.lang.IllegalArgumentException:参数值元素[com.theironyard.Entities]。Coffee@123ec0f1]与预期类型[com.theironyard.Entities.Tag(不适用)]不匹配

package com.theironyard.Repositories;
进口com.theironyard.Entities.Coffee;
导入org.springframework.data.domain.Page;
导入org.springframework.data.domain.Pageable;
导入org.springframework.data.jpa.repository.JpaRepository;
导入java.time.LocalDateTime;
导入java.util.List;
/**
*达里安·摩尔于2017年1月26日创作。
*/
公共接口咖啡库扩展了JpaRepository{
Coffee findFirstByName(字符串名称);
提交咖啡findBySubmitted(提交LocalDateTime);
列出findByNameContainingIgnoreCase(字符串搜索);
页面findAll(可分页可分页);
PageFindBytags(可分页、可分页、列表标记、提供);
}
//这是我的整个导航控制器类,包含所有导入和
//实现
包com.theironyard.Controllers;
导入com.theironyard.Command.RatingCommand;
进口com.theironyard.Entities.Coffee;
导入com.theironyard.Entities.Tag;
导入com.theironyard.Entities.User;
导入com.theironyard.Repositories.*;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.data.domain.Page;
导入org.springframework.data.domain.PageRequest;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.Model;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.RequestParam;
导入javax.servlet.http.HttpSession;
导入java.time.LocalDateTime;
导入java.util.ArrayList;
导入java.util.List;
/**
*达里安·摩尔于2017年1月26日创作。
*/
@控制器
公共类导航控制器{
公共静态最终字符串CURRENT_USER=“username”;
@自动连线
用户存储库用户存储库;
@自动连线
咖啡库咖啡库;
@自动连线
最近咖啡库最近咖啡库;
@自动连线
标记库标记库;
@自动连线
评级库评级库;
/**
*获取社区/主页
*@param会话
*@返回
*/
@RequestMapping(path=“/”,method=RequestMethod.GET)
公共字符串getCommunityPage(模型,HttpSession会话){
List coffee=coffeeRepository.findAll();
ArrayList recCoffee=新的ArrayList();
咖啡(c:咖啡){
if(c.getSubmitted().isBefore(LocalDateTime.now())和&c.getSubmitted().isAfter(LocalDateTime.now().minusDays(1))){
最近的咖啡储存库。保存(c);
添加(c);
}
}
model.addAttribute(“coffee”,coffee);
model.addAttribute(“最近”,recCoffee);
返回“社区页面”;
}
/**
*获取当前用户帐户页
*@param会话
*@返回
*/
@RequestMapping(path=“/user account”,method=RequestMethod.GET)
公共字符串getUserAccount(模型,HttpSession会话){
if(session.getAttribute(当前用户)==null){
返回“重定向:/user异常”;
}
User userId=userRepository.findFirstByUsername((字符串)session.getAttribute(当前用户));
model.addAttribute(“preferences”,userId.getPreferredCoffee());
返回“用户帐户”;
}
/**
*还不确定
*@param会话
*@返回
*/
@RequestMapping(path=“/user account”,method=RequestMethod.POST)
公共字符串用户帐户(HttpSession会话){
返回“用户帐户”;
}
/**
*获取特定咖啡及其基于所述咖啡ID的信息
*@param模型
*@param-id
*@返回
*/
@RequestMapping(path=“/coffee”,method=RequestMethod.GET)
公共字符串getCoffee(模型模型,HttpSession会话,int-id){
咖啡=coffeeRepository.findOne(id);
List tags=tagRepository.findAll();
model.addAttribute(“coffee”,coffee);
model.addAttribute(“tags”,coffee.getTags());
model.addAttribute(“rates”,coffee.getRatings());
返回“咖啡”;
}
/**
*以防万一法
*@param会话
*@param ratingCommand
*@param-id
*@返回
*/
@RequestMapping(path=“/coffee”,method=RequestMethod.POST)
公共字符串咖啡(HttpSession会话,RatingCommand RatingCommand,int-id){
Coffee coffeeId=coffeeRepository.findOne(id);
用户userId=userRepository.findOne(id);
return“重定向:/coffee?id=“+id;
}
/**
*实现咖啡列表的分页
*还将咖啡对象添加到咖啡列表中
*@param会话
*@param页
*@返回
*/
@RequestMapping(path=“/coffee list”,method=RequestMethod.GET)
公共字符串getCoffeeList(模型模型、HttpSession会话、字符串标记、@RequestParam(defaultValue=“0”)int页){
List tags=tagRepository.findAll();
佩奇咖啡;
如果(标记!=null){
//tagfilteredtag=tagRepository.findByDescription(Tag);
//List coffeeByTag=new ArrayList();
List filtered=coffeeRepository.findAll();
List filterByTag=new ArrayList();
用于(咖啡c:过滤){
c、 getTags();
for(标记t:c.getTags()){
if(t.getDescription().equalsIgnoreCase(标记)){
加上(c)项;
}
}
}
   package com.theironyard.Repositories;

   import com.theironyard.Entities.Coffee;
   import org.springframework.data.domain.Page;
   import org.springframework.data.domain.Pageable;




    import org.springframework.data.jpa.repository.JpaRepository;

    import java.time.LocalDateTime;
    import java.util.List;

/**
 * Created by darionmoore on 1/26/17.
 */
    public interface CoffeeRepository extends JpaRepository<Coffee, Integer> {
    Coffee findFirstByName(String name);
    Coffee findBySubmitted(LocalDateTime submitted);
    List<Coffee> findByNameContainingIgnoreCase(String search);
    Page<Coffee> findAll(Pageable pageable);
    Page<Coffee> findByTags(Pageable pageable, List<Coffee> taggedCoffee);

}


//Here is my entire Navigation controller Class with all imports and
//Implementations

    package com.theironyard.Controllers;

    import com.theironyard.Command.RatingCommand;
    import com.theironyard.Entities.Coffee;
    import com.theironyard.Entities.Tag;
    import com.theironyard.Entities.User;
    import com.theironyard.Repositories.*;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.domain.Page;
    import org.springframework.data.domain.PageRequest;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;

    import javax.servlet.http.HttpSession;
    import java.time.LocalDateTime;
    import java.util.ArrayList;
    import java.util.List;

/**
 * Created by darionmoore on 1/26/17.
 */
    @Controller
    public class NavigationController {
    public static final String CURRENT_USER = "username";

    @Autowired
    UserRepository userRepository;

    @Autowired
    CoffeeRepository coffeeRepository;

    @Autowired
    RecentCoffeeRepository recentCoffeeRepository;

    @Autowired
    TagRepository tagRepository;

    @Autowired
    RatingRepository ratingRepository;

    /**
     * Gets the community/home page
     * @param session
     * @return
     */
    @RequestMapping(path = "/", method = RequestMethod.GET)
    public String getCommunityPage(Model model, HttpSession session){
        List<Coffee> coffee = coffeeRepository.findAll();
        ArrayList <Coffee> recCoffee = new ArrayList<>();
        for(Coffee c : coffee){
            if(c.getSubmitted().isBefore(LocalDateTime.now()) && c.getSubmitted().isAfter(LocalDateTime.now().minusDays(1))){
                recentCoffeeRepository.save(c);
                recCoffee.add(c);
            }
        }

        model.addAttribute("coffee", coffee);
        model.addAttribute("recent", recCoffee);
        return "community-page";
    }

    /**
     * Gets the current users account page
     * @param session
     * @return
     */
    @RequestMapping(path = "/user-account", method = RequestMethod.GET)
    public String getUserAccount(Model model, HttpSession session){
        if(session.getAttribute(CURRENT_USER) == null){
            return "redirect:/user-exception";
        }
        User userId = userRepository.findFirstByUsername((String)session.getAttribute(CURRENT_USER));
        model.addAttribute("preferences", userId.getPreferredCoffee());
        return "user-account";
    }

    /**
     * Not sure about this yet
     * @param session
     * @return
     */
    @RequestMapping(path = "/user-account", method = RequestMethod.POST)
    public String userAccount(HttpSession session){
        return "user-account";
    }


    /**
     * Gets a specific coffee and its information based on the ID of said coffee
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(path = "/coffee", method = RequestMethod.GET)
    public String getCoffee(Model model, HttpSession session, int id){
        Coffee coffee = coffeeRepository.findOne(id);
        List tags = tagRepository.findAll();
        model.addAttribute("coffee", coffee);
        model.addAttribute("tags", coffee.getTags());
        model.addAttribute("rates", coffee.getRatings());
        return "coffee";
    }

    /**
     * Just in case method
     * @param session
     * @param ratingCommand
     * @param id
     * @return
     */
    @RequestMapping(path = "/coffee", method = RequestMethod.POST)
    public String Coffee(HttpSession session, RatingCommand ratingCommand, int id){
        Coffee coffeeId = coffeeRepository.findOne(id);
        User userId = userRepository.findOne(id);
        return "redirect:/coffee?id="+ id;
    }

    /**
     * Implement pageination for the coffee list
     * Also adds the Coffee object to the coffee-list
     * @param session
     * @param page
     * @return
     */
    @RequestMapping(path = "/coffee-list", method = RequestMethod.GET)
    public String getCoffeeList(Model model, HttpSession session, String tag, @RequestParam(defaultValue = "0") int page){
        List<Tag> tags = tagRepository.findAll();
        Page<Coffee> coffees;

        if(tag != null){
//            Tag filteredTag = tagRepository.findByDescription(tag);
//            List<Tag> coffeeByTag = new ArrayList<>();
            List<Coffee> filtered = coffeeRepository.findAll();
            List<Coffee> filterByTag = new ArrayList<>();
            for(Coffee c : filtered){
                c.getTags();
                for(Tag t : c.getTags()) {
                    if (t.getDescription().equalsIgnoreCase(tag)){
                        filterByTag.add(c);
                    }
                }
            }
            coffees = coffeeRepository.findByTags(new PageRequest(page, 10), filterByTag);
        }
        else{
            coffees = coffeeRepository.findAll(new PageRequest(page, 10));
        }

        if(coffees.hasPrevious()){
            model.addAttribute("prev", true);
            model.addAttribute("prevPageNum", page - 1);
        }

        if(coffees.hasNext()){
            model.addAttribute("next", true);
            model.addAttribute("nextPageNum", page + 1);
        }

        model.addAttribute("tags", tags);
        model.addAttribute("coffees", coffees);
        return "coffee-list";
    }

    /**
     * Just in case method
     * @param session
     * @return
     */
    @RequestMapping(path = "/coffee-list", method = RequestMethod.POST)
    public String coffeeList(HttpSession session){
        return "coffee-list";
    }

    /**
     * Just in case method
     * @param model
     * @param session
     * @return
     */
    @RequestMapping(path = "/about-us", method = RequestMethod.GET)
    public String getAboutUs(Model model, HttpSession session){
        return "about";
    }

    /**
     * Just in case method
     * @param session
     * @return
     */
    @RequestMapping(path = "/about-us", method = RequestMethod.POST)
    public String AboutUs(HttpSession session){
        return "redirect:/about-us";
    }

}

<I don't know what else to add so I'm adding things arbitrarily to make sure that I can submit this edit>