Skip to content
Advertisement

How to map an entity field whose name is a reserved word in JPA

@Column(name="open")

Using sqlserver dialect with hibernate.

[SchemaUpdate] Unsuccessful: create table auth_session (id numeric(19,0) identity not null, active tinyint null, creation_date datetime not null, last_modified datetime not null, maxidle int null, maxlive int null, open tinyint null, sessionid varchar(255) not null, user_id numeric(19,0) not null, primary key (id), unique (sessionid))
[SchemaUpdate] Incorrect syntax near the keyword 'open'.

I would have expected hibernate to use quoted identifier when creating the table.

Any ideas on how to handle this… other than renaming the field?

Advertisement

Answer

Had the same problem, but with a tablename called Transaction. If you set

hibernate.globally_quoted_identifiers=true

Then all database identifiers will be quoted.

Found my answer here Special character in table name hibernate giving error

And found all available settings here https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/appendices/Configurations.html

Could not find better docs for this though.

In my case the setting was in my Spring properties file. As mentioned in the comments, it could also be in other, hibernate related, configuration files.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement