P
P
P_Alexander2018-06-13 15:05:36
Java
P_Alexander, 2018-06-13 15:05:36

How to fix javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet?

Hello, I'm getting this error, how can I fix it?
In the model I return the Integer type in the service layer and in the Dao layer I accept the Integer type, in the database this field is set to the Integer type, where do I need to cast the types, I don’t understand?
JPQL query

@Override
    public Card findByCardNumber(Integer numberCard) {
        try {
            Card card = (Card) getEntityManager()
                    .createQuery("SELECT c FROM Card c WHERE c.number_card LIKE:number_card")
                    .setParameter("number_card", numberCard)
                    .getSingleResult();
            return card;
        }catch (NoResultException e){
            return null;
        }
    }

test method
@Test
    public void findByCardNumber() {
        Card card = cardService.findByCardNumber(1111111111);
        Integer a = card.getNumber_card();
        Integer b = 1111111111;
        assertEquals(b, a);
    }

2018-июн-13 14:45:37 PM [main] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42883
2018-июн-13 14:45:37 PM [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: operator does not exist: integer ~~ integer
  Подсказка: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Позиция: 178

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_gon, 2018-06-13
@P_Alexander

LIKE для Integer ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question