[Resolvido]Ajuda com JPQL e JPA (trabalho da faculdade)

2 respostas
G

Tentei fazer varias jpql, mas cheguei a conclusão de que não sei

tabela consulta com

`id` INT(10) NOT NULL AUTO_INCREMENT, `dataConsulta` VARCHAR(10) NOT NULL, `valorConsulta` DOUBLE NOT NULL, `crm` INT(10) NOT NULL, `cpf` INT(11) NULL DEFAULT NULL, PRIMARY KEY (`id`), INDEX `crm` (`crm`), INDEX `cpf` (`cpf`), CONSTRAINT `cpf` FOREIGN KEY (`cpf`) REFERENCES `paciente` (`cpf`), CONSTRAINT `crm` FOREIGN KEY (`crm`) REFERENCES `medico` (`crm`)

Gostaria de listar com um SELECT todos os registros desta tabela com um determinado crm de um textfield, mas não estou conseguindo

2 Respostas

esqueleto

kra se voce tiver usando hibernate pode fazer um hql. Para rodar o HQL abaixo tem que ter a classe Consulta mapeada. Se não resolver posta ai novamente a duvida. blz??

session.createQuery("select from Consulta c where c.crm = ?").setParamenter(1, crm).list();
G

estou usando as bibliotecas do EclipseLink.

coloquei um crm valido para testar e esta dando varios erros de Exception:
line 1:40 mismatched character ‘’ expecting set ‘1’…'9’
Exception in thread “AWT-EventQueue-0” java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [select c from Consulta c where c.crm = ?], line 0, column -1: unexpected end of query.
Internal Exception: NoViableAltException(-1@[792:1: comparisonExpressionRightOperand returns [Object node] : (n= arithmeticExpression | n= nonArithmeticScalarExpression | n= anyOrAllExpression );])

public List<Consulta> listaConsultaMedico(Integer crm) { EntityManager entity = getEntityManager(); List<Consulta> lista = null; lista = entity.createQuery("select c from Consulta c where c.crm = ?").setParameter(1, crm).getResultList(); return lista; }

Criado 11 de novembro de 2011
Ultima resposta 12 de nov. de 2011
Respostas 2
Participantes 2