Juan M Juan M - 10 months ago 42
Ajax Question

Internal Server Error on ajax GET request in Spring MVC

Hi everyone i'm new to spring MVC so i have little idea about the framework. All I'm trying to do is refresh a div in my view with items filtered by a hibernate query, which prints correctly to standard out.

For some reason I'm not aware of I get a 500; Internal server error when i try a get request via ajax.
I changed the return type in the controller, my original idea was to use the default index controller with an optional parameter.


<div id="itemListContainer">
<c:if test="${!empty items}">
<c:forEach items="${items}" var="item">
<c:url value="/showImage.htm" var="url">
<c:param name="id" value="${item.id}" />
<div id="${item.id}" class="col-lg-2 col-md-3 col-xs-6 thumb">
<img class="img-responsive" src="${url}" alt="${item.name}">
<input id="name_${item.id}" type="hidden" value="${item.name}">
<input id="name_${item.id}" type="hidden" value="${item.review}">
<c:if test="${!empty itemList}">
<h1>Nothing found</h1>

JS File

function filterItems(value) {


method: "GET",
//dataType: "json",
url: "filterItems.htm",
data: {
type: value
success: function (data) {
if (data) {
} else {
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);


@RequestMapping(value = "/filterItems", method = RequestMethod.GET)
public @ResponseBody List<Item> filterItems(@RequestParam(value = "type", required = false) String type) {
List<Item> items = new ArrayList<Item>();
try {
items = itemDao.getItems(type);

} catch (Exception e) {
return items;

Any help will be greatly appreciated. Thanks in advance!!

Answer Source

Once again, when it comes my little experience with hibernate, the error has nothing to do with Javascript, controller o DAO but with entity mapping.

My Item entity had an association with a User entity, and had to specify between lazy and eager loading of the association. In my case it was solved by adding lazy="true" to my xml file.