ChatCrawlersearch across public Telegram Open the app
J

Java Studio

9 January 2019
2019-01-09×
9 January 2019
@Override public Automotriz getAutomoriz(int id) throws Exception { try { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Automotriz> query = builder.createQuery(Automotriz.class); Root<Automotriz> automotriz = query.from(Automotriz.class); query.select(automotriz); ParameterExpression<Integer> parametro = builder.parameter(Integer.class); query.where(builder.gt(automotriz.get("id_automotriz"), parametro)); } catch (Exception e) { System.out.println(e); } return null; }
K
no se como retornar una entidad
query.select(automotriz).where(builder.gt(automotriz.get("id_automotriz"), parametro));
List<Automotriz> result = entityManager.createQuery(query).getResultList();
Por Q ni idea 😅😅
K
@Override public Automotriz getAutomoriz(int id) throws Exception { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<Automotriz> query = builder.createQuery(Automotriz.class); Root<Automotriz> automotriz = query.from(Automotriz.class); query.select(automotriz); TypedQuery<Automotriz> typedQuery = entityManager.createQuery(query); query.where(builder.gt(automotriz.get("id_automotriz"), id)); return (Automotriz) typedQuery.getResultList().get(id-1); }
Parece que lo único que quieres es recuperar la entidad por id
A
Si es así hay una forma más corta
K
Seguí la documentación
A
Pero tú buscas por id, por lo que un entityManager.find(Automotriz.class, id) debería haberte valido
@Override public Automotriz getAutomoriz(int id) throws Exception { TypedQuery<Automotriz> consulta = entityManager.createQuery("SELECT a from Automotriz a where a.id_automotriz = :idautomotriz",Automotriz.class); return(Automotriz) consulta.setParameter("idautomotriz", id).getSingleResult(); }
A
Tiene pinta de que no estás usando un ide, porque debería cantarte por el tipado
K
Фотография
click to show
A
Mejor al grupo, que para eso está
K
funciona excelente. Una ultima pregunta al realizar una relación manytomany con jpa puedo la tabla que se crea puedo agregarla una primary key o debo hacerlo a mano
K
dar una primary key a todas las tablas
A
Puedes dar una PK a cada tabla sin problemas. No suele ser buena idea tener tablas sin PK
Calendar: January 2019
MoTuWeThFrSaSu1234569758937101111213141516171831920521122232425262728293031
Archive by month
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog