Description of problem: Issue happens when hibernate runs schema validation when used in JBoss BPM 6.0.2 (JBoss EAP 6.1.1) context. Validation is passed in situtation when the table is not actually present. Version-Release number of selected component (if applicable): How reproducible: Steps to Reproduce: 1) create table/sequence as per the following sql file on "TEST" and "TEST1" user. https://access.redhat.com/jbossnetwork/restricted/softwareDownload.html?softwareId=30803&product=bpm.suite jboss-bpms-brms-6.0.2.GA-redhat-5-supplementary-tools/ddl-scripts/oracle/oracle-jbpm-schema.sql (2) create the following table on "TEST" user only. create table Content2 ( id number(19,0) not null, content blob, primary key (id) ); (3) backup data from Content to Contents on "TEST". create table Content2 ( id number(19,0) not null, content blob, primary key (id) ); insert into Content2 select * from Content; drop content; commit; (4) JBoss EAP (attached) 17:08:27,943 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 51) HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect 17:08:27,974 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (ServerService Thread Pool -- 51) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory 17:08:27,974 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 51) HHH000397: Using ASTQueryTranslatorFactory 17:08:28,021 INFO [org.hibernate.validator.internal.util.Version] (ServerService Thread Pool -- 51) HV000001: Hibernate Validator 4.3.1.Final-redhat-1 17:08:28,723 INFO [org.hibernate.tool.hbm2ddl.SchemaValidator] (ServerService Thread Pool -- 51) HHH000229: Running schema validator 17:08:28,723 INFO [org.hibernate.tool.hbm2ddl.SchemaValidator] (ServerService Thread Pool -- 51) HHH000102: Fetching database metadata 17:08:28,832 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST.ATTACHMENT 17:08:28,832 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000037: Columns: [id, attachmentcontentid, taskdata_attachments_id, attachment_size, attachedby_id, name, attachedat, contenttype, accesstype] 17:08:28,848 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST.BAMTASKSUMMARY 17:08:28,848 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000037: Columns: [duration, startdate, status, taskid, userid, createddate, taskname, enddate, optlock, processinstanceid, pk] 17:08:28,848 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST.BOOLEANEXPRESSION 17:08:28,848 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000037: Columns: [expression, id, escalation_constraints_id, type] * 17:08:28,863 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST1.CONTENT 17:08:28,863 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000037: Columns: [content, id] 17:08:28,863 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST.CONTEXTMAPPINGINFO 17:08:28,863 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000037: Columns: [context_id, mappingid, optlock, ksession_id] 17:08:28,879 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST.CORRELATIONKEYINFO 17:08:28,879 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000037: Columns: [keyid, name, optlock, processinstanceid] 17:08:28,895 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST.CORRELATIONPROPERTYINFO 17:08:28,895 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000037: Columns: [name, value, correlationkey_keyid, optlock, propertyid] 17:08:28,895 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] (ServerService Thread Pool -- 51) HHH000261: Table found: TEST.DEADLINE * I use the "TEST" user , but TEST1.CONTENT is validated. (5) Access [1] http://localhost:8080/BPMSFSAppHoshi_War/doProcess?CTLSCN=DispRegister [2] Select "ビジネスプロセス定義2" [3] Click "登録" [4] JBWEB000071: root cause java.sql.SQLSyntaxErrorException: ORA-00942: 表またはビューが存在しません。 oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1044) oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1329) oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584) oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3665) oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1352) org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133) org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58) org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3058) org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3499) org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88) org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354) org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275) org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:328) org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234) org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404) org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:112) org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76) com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273) com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93) com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162) com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165) com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126) com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75) org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:167) jp.co.Hitachi.soft.oss.bpms.common.logic.BPMSAppRuntime.commit(BPMSAppRuntime.java:26) jp.co.Hitachi.soft.oss.bpms.common.logic.BPMSManager.commit(BPMSManager.java:119) jp.co.Hitachi.soft.oss.bpms.fs.action.BPMSFSAppAction.doIt(BPMSFSAppAction.java:270) jp.co.Hitachi.soft.oss.bpms.fs.action.BPMSFSAppAction.doPost(BPMSFSAppAction.java:81) javax.servlet.http.HttpServlet.service(HttpServlet.java:754) javax.servlet.http.HttpServlet.service(HttpServlet.java:847) jp.co.Hitachi.soft.oss.common.EncodingFilter.doFilter(EncodingFilter.java:30) Actual results: "HHH000261: Table found: TEST1.CONTENT" message is shown Expected results: validation error Additional info: env: JBoss EAP 6.1.1 JBoss BPM 6.0.2 Oracle 11g R2 Windows 2008 R2 SP1 Oracle JDK 1.7 u65
This can also be reproduced using H2 database and jboss-hibernate4 quickstart project. Steps: 1) in the quickstart project, configure hibernate.hbm2ddl.auto=validate and a database connection to standalone H2 database (default user) 2) run standalone database, create MemberHibernate4Demo table, but in different schema than PUBLIC 3) build and deploy quickstart on EAP (hibernate validation succeeds) 4) visit the quickstart in browser (http://127.0.0.1:8080/jboss-hibernate4/) => following exception is thrown: org.h2.jdbc.JdbcSQLException: Table "MEMBERHIBERNATE4DEMO" not found; SQL statement: select this_.id as id1_0_0_, this_.address as address2_0_0_, this_.email as email3_0_0_, this_.name as name4_0_0_, this_.phone_number as phone_nu5_0_0_ from MemberHibernate4Demo this_ order by this_.name asc [42102-168] at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) at org.h2.message.DbException.get(DbException.java:169) at org.h2.message.DbException.get(DbException.java:146) at org.h2.command.Parser.readTableOrView(Parser.java:4770) at org.h2.command.Parser.readTableFilter(Parser.java:1084) at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1690) at org.h2.command.Parser.parseSelectSimple(Parser.java:1797) at org.h2.command.Parser.parseSelectSub(Parser.java:1684) at org.h2.command.Parser.parseSelectUnion(Parser.java:1527) at org.h2.command.Parser.parseSelect(Parser.java:1515) at org.h2.command.Parser.parsePrepared(Parser.java:405) at org.h2.command.Parser.parse(Parser.java:279) at org.h2.command.Parser.parse(Parser.java:251) at org.h2.command.CommandContainer.recompileIfRequired(CommandContainer.java:52) at org.h2.command.CommandContainer.query(CommandContainer.java:82) at org.h2.command.Command.executeQuery(Command.java:191) at org.h2.server.TcpServerThread.process(TcpServerThread.java:306) at org.h2.server.TcpServerThread.run(TcpServerThread.java:149) at java.lang.Thread.run(Thread.java:745) org.h2.engine.SessionRemote.done(SessionRemote.java:567) org.h2.command.CommandRemote.executeQuery(CommandRemote.java:151) org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:109) org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79) org.hibernate.loader.Loader.getResultSet(Loader.java:2062) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1859) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838) org.hibernate.loader.Loader.doQuery(Loader.java:906) ... The problem only occurs when schema is not defined in @Table annotation. Hibernate validator searches for all tables with name, schema and catalog defined by the @Table annotation. Since the latter two are null, all tables with given name are found, no matter which catalog they are in. First table in order is then accepted. When performing queries (criteria in this case), only information from @Table annotation is used, so jdbc is given unqualified table name and throws an exception if given table is not present in default schema.
Hibernate Jira issue: https://hibernate.atlassian.net/browse/HHH-9550
This will not be fixed in EAP 6.4.0 ER1. If it is considered a blocker, it may be able to be fixed for ER2. The workaround is to provide the default schema/catalog in the @Table annotation.
The fix for HHH-9550 was to the master branch only. I've cloned that issue to HHH-9718 for fixing in 4.2 and 4.3 branches.