title: How to read out a column with a colon (:) in its name in hibernate and postgresql
body: <p>sorry for this maybe being a very easy question, I searched and didn't find anything about my specific case. </p>
  
  <p>I am given a postgre database in which I have a table that has a column called:</p>
  
  <p>addr:city</p>
  
  <p>Since I cant use colons in java classvariables I tried to represent it this way: </p>
  
  <pre><code>@Column(name = "addr:city")
  private String addrCity;
  </code></pre>
  
  <p>Sadly this didn't work, I get the following exception (I am sorry for the german language in the exception text, I don't know why it is this way - translated it means a Syntax error at the : (colon)): </p>
  
  <blockquote>
    <p>ERROR: FEHLER: Syntaxfehler bei »:«   Position: 52 Exception in thread
    "main" org.hibernate.exception.SQLGrammarException: FEHLER:
    Syntaxfehler bei »:«   Position: 52   at
    org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
      at
    org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
      at
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      at
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      at
    org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
      at
    org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
      at $Proxy12.executeQuery(Unknown Source)    at
    org.hibernate.loader.Loader.getResultSet(Loader.java:1978)    at
    org.hibernate.loader.Loader.doQuery(Loader.java:829)  at
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
      at org.hibernate.loader.Loader.doList(Loader.java:2463)     at
    org.hibernate.loader.Loader.doList(Loader.java:2449)  at
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2279)    at
    org.hibernate.loader.Loader.list(Loader.java:2274)    at
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)   at
    org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
      at
    org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1115)   at
    org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)     at
    database.BerlinPolygonDAO.getBerlinLocationByID(BerlinPolygonDAO.java:52)
      at databaseAccess.Tester.main(Tester.java:33) Caused by:
    org.postgresql.util.PSQLException: FEHLER: Syntaxfehler bei »:«<br>
    Position: 52  at
    org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
      at
    org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
      at
    org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
      at
    org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
      at
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
      at
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)     at
    org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
      ... 16 more</p>
  </blockquote>
  
  <p>I read in some other posts that I should escape it the way below, but it did not work for me (exception that simply says that there is a syntax error with the "\") </p>
  
  <pre><code>@Column(name = "addr\\:city")
  private String addrCity;
  </code></pre>
  
  <p>It also didn't help to use two colons: </p>
  
  <pre><code>@Column(name = "addr::city")
  private String addrCity;
  </code></pre>
  
  <p>Then I get an exception, that the column "addr" (so without the colon and the rest) doesn't exist. </p>
  
  <p>Can anyone tell me what I need to do for reading out this column? Thanks a lot for every thought and idea you're sharing with me. </p>
  
  <p>EDIT: I found <a href="https://stackoverflow.com/questions/4940959/problem-with-a-column-name-contains-a-colon-in-postgresql">this</a> related question that deals with the exact same column I'm dealing with now and the problem with the colon, but <strong>not</strong> in hibernate. I'm thinking if this might help somehow. </p>