I've the following Entity
{code:java} @Entity @Table(name="cod__postales") public class CodigoPostal {
@Id @GeneratedValue private Long registro;
@Column(name = "`POST_Nº_CODIGO`", length = 6, nullable = false) private String codigo = " ";
@Column(name = "POST_DESCRIP", length = 30, nullable = false) private String descripcion = " ";
@Column(name = "POST_ZONA_ASIG", length = 2, nullable = false) private String zona = " "; ... } {code}
Also I've the following Spring JPA Repository:
{code:java} public interface CodigoPostalRepository extends JpaRepository<CodigoPostal, Long> { CodigoPostal findOneByCodigo(String codigo); } {code}
As you can see, there is a special character on the first column name 'º'. The problem is that, when I call to repo.findOneByCodigo() method, the following SQL is generated:
{code:sql} select codigopost0_.registro as registro1_2_, codigopost0_.`post_nº_codigo` as post_nº_2_2_, codigopost0_.post_descrip as post_des3_2_, codigopost0_.post_zona_asig as post_zon4_2_ from cod__postales codigopost0_ where codigopost0_.`post_nº_codigo`=? {code}
The problem is that sql gives an error because of the name Hibernate assings to that column: as post_nº_2_2_. The generated SQL should be put inside `` the same way I've put the column name inside the @Column annotation
Aditional Data:
{code:console} 2016-02-02 11:53:07.372 DEBUG 8185 --- [ main] o.h.h.internal.ast.QueryTranslatorImpl : --- HQL AST --- \-[QUERY] Node: 'query' +-[SELECT_FROM] Node: 'SELECT_FROM' | +-[FROM] Node: 'from' | | \-[RANGE] Node: 'RANGE' | | +-[DOT] Node: '.' | | | +-[DOT] Node: '.' | | | | +-[DOT] Node: '.' | | | | | +-[IDENT] Node: 'com' | | | | | \-[IDENT] Node: 'eunasa' | | | | \-[IDENT] Node: 'domain' | | | \-[IDENT] Node: 'CodigoPostal' | | \-[ALIAS] Node: 'generatedAlias0' | \-[SELECT] Node: 'select' | \-[IDENT] Node: 'generatedAlias0' \-[WHERE] Node: 'where' \-[EQ] Node: '=' +-[DOT] Node: '.' | +-[IDENT] Node: 'generatedAlias0' | \-[IDENT] Node: 'codigo' \-[COLON] Node: ':' \-[IDENT] Node: 'param0' {code}
{code:console} 2016-02-02 11:53:07.377 DEBUG 8185 --- [ main] o.h.h.internal.ast.QueryTranslatorImpl : --- SQL AST --- \-[SELECT] QueryNode: 'SELECT' querySpaces (cod__postales) +-[SELECT_CLAUSE] SelectClause: '{select clause}' | +-[ALIAS_REF] IdentNode: 'codigopost0_.registro as registro1_2_' {alias=generatedAlias0, className=com.eunasa.domain.CodigoPostal, tableAlias=codigopost0_} | \-[SQL_TOKEN] SqlFragment: 'codigopost0_.`post_nº_codigo` as post_nº_2_2_, codigopost0_.post_descrip as post_des3_2_, codigopost0_.post_zona_asig as post_zon4_2_' +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[generatedAlias0], fromElementByTableAlias=[codigopost0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]} | \-[FROM_FRAGMENT] FromElement: 'cod__postales codigopost0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=generatedAlias0,role=null,tableName=cod__postales,tableAlias=codigopost0_,origin=null,columns={,className=com.eunasa.domain.CodigoPostal}} \-[WHERE] SqlNode: 'where' \-[EQ] BinaryLogicOperatorNode: '=' +-[DOT] DotNode: 'codigopost0_.`post_nº_codigo`' {propertyName=codigo,dereferenceType=PRIMITIVE,getPropertyPath=codigo,path=generatedAlias0.codigo,tableAlias=codigopost0_,className=com.eunasa.domain.CodigoPostal,classAlias=generatedAlias0} | +-[ALIAS_REF] IdentNode: 'codigopost0_.registro' {alias=generatedAlias0, className=com.eunasa.domain.CodigoPostal, tableAlias=codigopost0_} | \-[IDENT] IdentNode: 'codigo' {originalText=codigo} \-[NAMED_PARAM] ParameterNode: '?' {name=param0, expectedType=org.hibernate.type.StringType@1e26bf02} {code}
|
|