Erro de mapeamento

Java

10/03/2017

GRAVE: Servlet.service() for servlet [appServlet] in context with path [/extensao] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Professor is not mapped [ SELECT p FROM Professor p]] with root cause
org.hibernate.hql.ast.QuerySyntaxException: Professor is not mapped [ SELECT p FROM Professor p]

Classe Professor

package br.newtonpaiva.extensao.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tb_professor")
public class Professor {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long cod_professor;
private Long nom_nome;

public Long getCod_professor() {
return cod_professor;
}

public void setCod_professor(Long cod_professor) {
this.cod_professor = cod_professor;
}

public Long getNom_nome() {
return nom_nome;
}

public void setNom_nome(Long nom_nome) {
this.nom_nome = nom_nome;
}

}

Classe controller

package br.newtonpaiva.extensao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
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 br.newtonpaiva.extensao.model.Professor;
import br.newtonpaiva.extensao.model.ProfessorRepository;

@Controller
@RequestMapping("professores")
public class ProfessorController {

@Autowired
ProfessorRepository repository;

@RequestMapping(method = RequestMethod.GET)
public String index(Model model) {

List<Professor> listaProfessores = repository.listar();

model.addAttribute("listaProfessores", listaProfessores);

return "professores";
}

}


Classe Repository

package br.newtonpaiva.extensao.model;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

@Repository
public class ProfessorRepository {

@PersistenceContext
private EntityManager manager;

/**
* Lista todos os professores
*/
@SuppressWarnings("unchecked")
public List<Professor> listar() {
return manager.createQuery("SELECT p FROM Professor p").getResultList();
}

/**
* Lista todos os professores por nome
*/
@SuppressWarnings("unchecked")
public List<Professor> listarNome(String professor) {
return manager.createQuery("SELECT p FROM Professor p WHERE p.nom_nome LIKE '%" + professor + "%' ")
.getResultList();
}

}
Guilherme Lopes

Guilherme Lopes

Curtidas 0
POSTAR