-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Schema change at Runtime
PostPosted: Mon Oct 24, 2005 7:13 pm 
Newbie

Joined: Mon Oct 24, 2005 6:34 pm
Posts: 14
Location: Guadalajara, Jalisco. México.
Hello, I've just downloaded a brand new jBoss 4.0.3 with the most recent Hibernate deployer for EJB3 and managed to deploy some EntityBeans using jBoss and Hibernate annotations, however when trying to change the database schema at runtime I get an error on DatabaseMetadata. My system is very big so normalization to only one schema is not an option, and concurrent calls to the datasource must share diferent schemas, I've tried using:
Code:
Map map = new HashMap();
map.put("hibernate.default_schema","schema1");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("mypersistenceunit",map);


wich partially works, since as you can see on the following StackTrace is aware of the schema change during the whole thing but on the DatabaseMetadata, where Metadata comes from "meta = connection.getMetaData();" acording to hibernate sourcecode org.hibernate.tool.hbm2ddl.DatabaseMetadata.java on the constructor. The next lines on the debug show inconsistency errors with the schema and tables structure, the cause: it's comparing data cached on the connection object from the pool with the schema name provided on the config map at runtime so no tables are created. If I manually create the tables, the schema change runs just fine, but the comparation errors still happen generating warnings, and I'm not certain it will not bring problems later.


Take a look at the Log, the schema is suppossed to be "schema2" properly recognized on the first lines of the console output, same as the last ones, yet the first appearence of TableMetadata ouputs the last used schema1 before the schema change took place. The debugging mini app is a Person-Account-Bank on wich I wanted to try the schema change and failed.


Is this an Hibernate Issue ? Will it be solved ? Ever ?

There is an already posted similar bug at
http://opensource2.atlassian.com/projects/hibernate/browse/HHH-735
for version 3.1beta1 and beta2 of hibernate and a propositive patch wich claims to solve this issue, but does not seem to be implemented on later releases of hibernate.


Thanks.
Luis D. Rangel T.
Software Architect


Hibernate version: 3.1rc2
AppServer jBoss 4.0.3
Database PostgreSQL 8.0.3
Full stack trace of any exception that occurs:
Code:
14:01:59,578 INFO  [Configuration] processing extends queue
14:01:59,593 INFO  [Configuration] processing collection mappings
14:01:59,609 INFO  [Configuration] processing association property references
14:01:59,640 INFO  [Configuration] processing foreign key constraints
14:01:59,671 INFO  [Configuration] processing extends queue
14:01:59,687 INFO  [Configuration] processing collection mappings
14:01:59,718 INFO  [Configuration] processing association property references
14:01:59,734 INFO  [Configuration] processing foreign key constraints
14:01:59,750 INFO  [NamingHelper] JNDI InitialContext properties:{}
14:01:59,781 INFO  [DatasourceConnectionProvider] Using datasource: java:/PostgresDS
14:01:59,796 INFO  [SettingsFactory] RDBMS: PostgreSQL, version: 8.0.3
14:01:59,828 INFO  [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.1devel JDBC3 with SSL (build 400)
14:01:59,843 INFO  [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
14:01:59,859 INFO  [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
14:01:59,890 INFO  [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
14:01:59,937 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): disabled
14:01:59,953 INFO  [SettingsFactory] Automatic session close at end of transaction: disabled
14:01:59,968 INFO  [SettingsFactory] JDBC batch size: 15
14:02:00,000 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabled
14:02:00,015 INFO  [SettingsFactory] Scrollable result sets: enabled
14:02:00,031 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
14:02:00,062 INFO  [SettingsFactory] Connection release mode: auto
14:02:00,078 INFO  [SettingsFactory] Default schema: schema2
14:02:00,109 INFO  [SettingsFactory] Default batch fetch size: 1
14:02:00,125 INFO  [SettingsFactory] Generate SQL with comments: disabled
14:02:00,156 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
14:02:00,171 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
14:02:00,187 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
14:02:00,234 INFO  [SettingsFactory] Query language substitutions: {}
14:02:00,250 INFO  [SettingsFactory] Second-level cache: enabled
14:02:00,265 INFO  [SettingsFactory] Query cache: disabled
14:02:00,296 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
14:02:00,312 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
14:02:00,343 INFO  [SettingsFactory] Structured second-level cache entries: disabled
14:02:00,375 INFO  [SettingsFactory] Statistics: disabled
14:02:00,390 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: enabled
14:02:00,406 INFO  [SettingsFactory] Default entity-mode: POJO
14:02:00,453 INFO  [SessionFactoryImpl] building session factory
14:02:00,562 INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
14:02:00,578 INFO  [SchemaUpdate] Running hbm2ddl schema update
14:02:00,609 INFO  [SchemaUpdate] fetching database metadata
14:02:00,703 INFO  [SchemaUpdate] updating schema
14:02:00,718 INFO  [Configuration] processing extends queue
14:02:00,750 INFO  [Configuration] processing collection mappings
14:02:00,750 INFO  [Configuration] processing association property references
14:02:00,781 INFO  [Configuration] processing foreign key constraints
14:02:01,015 INFO  [TableMetadata] table found: schema1.account
14:02:01,031 INFO  [TableMetadata] columns: [idbank, idaccount, idperson]
14:02:01,046 INFO  [TableMetadata] foreign keys: [fkb9d38a2d6532c292, fkb9d38a2d13c8ce44]
14:02:01,078 INFO  [TableMetadata] indexes: [account_pkey]
14:02:01,171 INFO  [TableMetadata] table found: schema1.bank
14:02:01,203 INFO  [TableMetadata] columns: [idbank, name]
14:02:01,203 INFO  [TableMetadata] foreign keys: []
14:02:01,234 INFO  [TableMetadata] indexes: [bank_pkey]
14:02:01,343 INFO  [TableMetadata] table found: schema1.person
14:02:01,359 INFO  [TableMetadata] columns: [idperson, name]
14:02:01,375 INFO  [TableMetadata] foreign keys: []
14:02:01,406 INFO  [TableMetadata] indexes: [person_pkey]
14:02:01,437 INFO  [DatabaseMetadata] table not found: schema2.account_id_seq
14:02:01,468 INFO  [DatabaseMetadata] table not found: schema2.bank_id_seq
14:02:01,484 INFO  [DatabaseMetadata] table not found: schema2.person_id_seq
14:02:01,500 ERROR [SchemaUpdate] Unsuccessful: create sequence schema2.account_id_seq
14:02:01,546 ERROR [SchemaUpdate] ERROR: relation "account_id_seq" already exists
14:02:01,578 ERROR [SchemaUpdate] Unsuccessful: create sequence schema2.bank_id_seq
14:02:01,593 ERROR [SchemaUpdate] ERROR: relation "bank_id_seq" already exists
14:02:01,625 ERROR [SchemaUpdate] Unsuccessful: create sequence schema2.person_id_seq
14:02:01,656 ERROR [SchemaUpdate] ERROR: relation "person_id_seq" already exists
14:02:01,687 INFO  [SchemaUpdate] schema update complete
14:02:01,703 INFO  [SessionFactoryImpl] Checking 0 named queries
14:02:01,765 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
14:02:01,796 ERROR [JDBCExceptionReporter] Batch entry 0 insert into schema2.bank (name, idBank) values (Fri Oct 21 14:02:01 CDT 2005, 2) was aborted.  Call getNextException to see the cause.
14:02:01,859 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: 42P01
14:02:01,890 ERROR [JDBCExceptionReporter] ERROR: relation "schema2.bank" does not exist
14:02:01,921 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:200)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:91)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
        at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:169)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2038)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2417)
        at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:344)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:36)
        at org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:90)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into schema2.bank (name, idBank) values (Fri Oct 21 14:02:01 CDT 2005, 2) was aborted.
Call getNextException to see the cause.
        at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2392)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1257)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:334)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2451)
        at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:487)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
        ... 41 more
14:02:03,531 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:200)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:91)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
        at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:169)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2038)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2417)
        at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:877)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:344)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:36)
        at org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:90)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into schema2.bank (name, idBank) values (Fri Oct 21 14:02:01 CDT 2005, 2) was aborted.
Call getNextException to see the cause.
        at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2392)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1257)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:334)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2451)
        at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:487)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
        ... 41 more

Name and version of the database you are using:
Debug level Hibernate log excerpt: DEBUG

Code:
[url][/url][url][/url][url][/url]


Top
 Profile  
 
 Post subject: Small Patch
PostPosted: Tue Oct 25, 2005 6:19 pm 
Newbie

Joined: Mon Oct 24, 2005 6:34 pm
Posts: 14
Location: Guadalajara, Jalisco. México.
Hello there, it's me again. I've changed "table.getSchema()" wich comes from the connection object for "defaultSchema" wich comes from systemproperties changes by me at runtime, now tables are generated even during schema changes at runtime, but sequence generation are still generating small warnings wich I still don't like. The file bugging me is package org.hibernate.cfg.Configuration.java altough it probably can be solved in a more elegant way somewhere else.

_________________
____________________________

The three programmer's virtues :
Lazyness, Impatience and Hubris.
- PerlManpages -
____________________________


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.