@Where annotation with globally_quoted_identifiers causes Unable to determine TableReference Exception
Description
Attachments
- 24 Jun 2022, 02:40 PM
relates to
Activity
Andrea Boriero June 27, 2022 at 8:27 AM
Hi @Rick Tuk ,
thanks a lot, I managed to reproduce the issue!
Rick Tuk June 24, 2022 at 2:47 PM
configOverrides:
jakarta.persistence.jdbc.url => jdbc:mariadb://localhost:3306/rosetta?autoReconnect=true&useMysqlMetadata=true
jakarta.persistence.jdbc.driver => org.mariadb.jdbc.Driver
hibernate.dialect => org.hibernate.dialect.MariaDBDialect
jakarta.persistence.jdbc.user => username
jakarta.persistence.jdbc.password => pasword
hibernate.globally_quoted_identifiers => true
hibernate.show_sql => false
hibernate.format_sql => false
hibernate.jdbc.use_streams_for_binary => false
hibernate.current_session_context_class => org.hibernate.context.internal.ThreadLocalSessionContext
hibernate.hikari.minimumIdle => 2
hibernate.hikari.maximumPoolSize => 10
hibernate.hikari.connectionTimeout => 10000
hibernate.hikari.idleTimeout => 120000
hibernate.hikari.maxLifetime => 250000
hibernate.hikari.validationTimeout => 5000
Andrea Boriero June 24, 2022 at 1:29 PM
Hi @Rick Tuk ,
I was not able to create a reproducer with the information you provided, can you also provide the persitence.xml
and the values in configOverrides
?
Thanks
Using the following entity
@Entity @Table(name = "nonce") @Where(clause = "`used` IS NULL") public class Nonce { @Id @Column(name = "nonce", unique = true, nullable = false, insertable = true, updatable = false) private String nonce = null; @Column(name = "sent", unique = false, nullable = false, insertable = true, updatable = false) private ZonedDateTime sent = ZonedDateTime.now(ZoneId.systemDefault()); @Column(name = "used", unique = false, nullable = true, insertable = true, updatable = true) private ZonedDateTime used = null; public Nonce() { super(); } public Nonce(String nonce) { this.setNonce(nonce); this.setSent(ZonedDateTime.now(ZoneId.systemDefault())); } public String getNonce() { return this.nonce; } private void setNonce(String nonce) { this.nonce = nonce; } public ZonedDateTime getSent() { return this.sent; } private void setSent(ZonedDateTime sent) { this.sent = sent; } public ZonedDateTime getUsed() { return this.used; } public void setUsed() { this.used = ZonedDateTime.now(ZoneId.systemDefault()); } }
We create an entity manager when starting the application
return Persistence.createEntityManagerFactory( persistenceUnitName, configOverrides ).createEntityManager();
Trying to create the entity manager fails with the following exception:
Caused by: org.hibernate.sql.ast.tree.from.UnknownTableReferenceException: Unable to determine TableReference (`nonce`) for `null` at org.hibernate.sql.ast.tree.from.AbstractColumnReferenceQualifier.resolveTableReference(AbstractColumnReferenceQualifier.java:45) at org.hibernate.sql.ast.tree.from.ColumnReferenceQualifier.resolveTableReference(ColumnReferenceQualifier.java:20) at org.hibernate.persister.entity.AbstractEntityPersister.applyWhereRestrictions(AbstractEntityPersister.java:4140) at org.hibernate.persister.entity.AbstractEntityPersister.applyBaseRestrictions(AbstractEntityPersister.java:4129) at org.hibernate.loader.ast.internal.LoaderSelectBuilder.applyFiltering(LoaderSelectBuilder.java:631) at org.hibernate.loader.ast.internal.LoaderSelectBuilder.generateSelect(LoaderSelectBuilder.java:481) at org.hibernate.loader.ast.internal.LoaderSelectBuilder.createSelect(LoaderSelectBuilder.java:176) at org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl.createLoadPlan(SingleIdEntityLoaderStandardImpl.java:180) at org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl.prepare(SingleIdEntityLoaderStandardImpl.java:54) at org.hibernate.persister.entity.AbstractEntityPersister.prepareLoader(AbstractEntityPersister.java:4274) at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:4266) at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:236) at org.hibernate.metamodel.internal.RuntimeMetamodelsImpl.finishInitialization(RuntimeMetamodelsImpl.java:60) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:308) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:415) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1425) ... 26 common frames omitted