Map table fields beginning with number

0

Hello, I'm having trouble mapping the tables in a database where column names start with number.

Here is an example of how I tried, but to no avail.

@Entity
@Table(name = "A_MOT025")
public class Motorista {
    @Id
@Column(name = "[0251CODIG]", columnDefinition = "SMALLINT")
private Integer codigo;

@Column(name = "[0252NOMMO]", columnDefinition = "CHAR")
private String nome;

I tried that too and I did not succeed.

@Entity
@Table(name = "A_MOT025")
public class Motorista {
    @Id
@Column(name = "\"0251CODIG\"", columnDefinition = "SMALLINT")
private Integer codigo;

@Column(name = "\"0252NOMMO\"", columnDefinition = "CHAR")
private String nome;

Without making any query it does not generate error, but when I will make this query below, the following error is generated.

public static void main(String[] args) {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("PedidoPU");
    EntityManager manager = factory.createEntityManager();
    EntityTransaction trx = manager.getTransaction();
    try {
        Query query = manager.createQuery("SELECT c FROM Motorista c");
        List<Motorista> resposta = query.getResultList();
        System.out.println(resposta.toString());
    } catch (RuntimeException e) {
        throw e;
    }    
    manager.close();
}

I have this error:

2016-09-22 14:09:28,637 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] SQL Error: 6002, SQLState: 42000
2016-09-22 14:09:28,637 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] [DBMaker] syntax error near or at ".'"
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:492)
    at Teste.main(Teste.java:24)
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1927)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1896)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1874)
    at org.hibernate.loader.Loader.doQuery(Loader.java:919)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
    at org.hibernate.loader.Loader.doList(Loader.java:2610)
    at org.hibernate.loader.Loader.doList(Loader.java:2593)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2422)
    at org.hibernate.loader.Loader.list(Loader.java:2417)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216)
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1339)
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
    at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483)
    ... 1 more
Caused by: java.sql.SQLException: [DBMaker] syntax error near or at ".'"
    at dbmaker.sql.JdbcOdbcAPI.createSQLException(JdbcOdbcAPI.java:3032)
    at dbmaker.sql.JdbcOdbcAPI.checkError(JdbcOdbcAPI.java:3092)
    at dbmaker.sql.JdbcOdbcAPI.jdbcPrepare(JdbcOdbcAPI.java:677)
    at dbmaker.sql.JdbcOdbcConnection.preStatement(JdbcOdbcConnection.java:757)
    at dbmaker.sql.JdbcOdbcConnection.prepareStatement(JdbcOdbcConnection.java:350)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172)
    
asked by anonymous 22.02.2018 / 20:36

0 answers