-->
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.  [ 3 posts ] 
Author Message
 Post subject: MySQL schema issue when migrating Hibernate 4 to 5
PostPosted: Thu Sep 29, 2016 8:54 am 
Newbie

Joined: Thu Sep 29, 2016 8:51 am
Posts: 2
Hello,

we have just upgraded from WildFly 9 to 10 and therefore also upgraded from Hibernate 4 to 5.
Our application uses entities that are derived from a abstract super entity that has a generated id field.
The super class looks like this:

Code:
@MappedSuperclass
@Access(AccessType.FIELD)
@SqlResultSetMapping(name = EntityId.rsmId,
   columns = { @ColumnResult(name = "id", type = Long.class) })
public abstract class EntityId
{
   @GeneratedValue(strategy = GenerationType.TABLE, generator = "generator1")
   @TableGenerator(name = "generator1",
      pkColumnValue = "g1",
      initialValue = 0, allocationSize = 1000,
      schema = "schema2", table = "sysidgenerator", // MySQL
      pkColumnName = "gen_key", valueColumnName = "gen_val")
   @Column(name = "id")
   @Id
   private Long id;
   
[...]
}

and our datasource is configured like this:

Code:
<xa-datasource jndi-name="java:jboss/datasources/MTDS" pool-name="MTDS" enabled="true" use-ccm="false">
   <xa-datasource-property name="URL">
      jdbc:mysql://server:3306/schema
   </xa-datasource-property>
   <driver>com.mysql</driver>
   <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
   <xa-pool>
      <min-pool-size>3</min-pool-size>
      <max-pool-size>40</max-pool-size>
      <is-same-rm-override>false</is-same-rm-override>
      <interleaving>false</interleaving>
      <pad-xid>false</pad-xid>
      <wrap-xa-resource>false</wrap-xa-resource>
   </xa-pool>
   <security>
      <user-name>user</user-name>
      <password>password</password>
   </security>
   <validation>
      <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
      <validate-on-match>false</validate-on-match>
      <background-validation>true</background-validation>
      <background-validation-millis>15000</background-validation-millis>
      <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
   </validation>
   <statement>
      <prepared-statement-cache-size>0</prepared-statement-cache-size>
      <share-prepared-statements>false</share-prepared-statements>
   </statement>
</xa-datasource>


With Hibernate 4 everything worked perfect. After the upgrade we get the following error:

Code:
ERROR [x.y.z] (default task-13) Caught exception.: javax.ejb.EJBTransactionRolledbackException: org.hibernate.HibernateException: Could not apply work
Caused by: org.hibernate.HibernateException: Unable to perform isolated work
   at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.doTheWork(JtaIsolationDelegate.java:139)
   at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.doTheWorkInNewTransaction(JtaIsolationDelegate.java:100)
   ... 253 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'schema.sysidgenerator' doesn't exist
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
   at com.mysql.jdbc.Util.getInstance(Util.java:384)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
   at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeQuery(PreparedStatementWrapper.java:844)
   at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504)
   at org.hibernate.id.enhanced.TableGenerator.executeQuery(TableGenerator.java:639)
   at org.hibernate.id.enhanced.TableGenerator.access$400(TableGenerator.java:127)
   at org.hibernate.id.enhanced.TableGenerator$1$1.execute(TableGenerator.java:541)
   at org.hibernate.id.enhanced.TableGenerator$1$1.execute(TableGenerator.java:531)
   at org.hibernate.jdbc.WorkExecutor.executeReturningWork(WorkExecutor.java:55)
   at org.hibernate.jdbc.AbstractReturningWork.accept(AbstractReturningWork.java:34)
   at org.hibernate.resource.transaction.backend.jta.internal.JtaIsolationDelegate.doTheWork(JtaIsolationDelegate.java:133)
   ... 254 more


For some reason Hibernate is now looking for the table 'schema.sysidgenerator' and not for 'schema2.sysidgenerator' like it is configured in the @TableGenerator.

What do we have to do to fix this?
Suggestions appreciated.

Regards
Eustachius


Top
 Profile  
 
 Post subject: Re: Missing table after Hibernate Upgrade
PostPosted: Thu Sep 29, 2016 9:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I think that HHH-10408 is what you are talking about here.

There are more details in HHH-9714:

Quote:
MySQL/MariaDB do not support schemas, they support catalogs. I know it is confusing because the command line lets you say CREATE SCHEMA, but their docs are very clear that this is just a "synonym" for CREATE DATABASE. And the JDBC driver only supports catalogs. In fact their DatabaseMetaData returns false for all {{#supportsSchemasIn?} methods, and true for {{#supportsCatalogsIn?).

This may have been a change from older versions of Hibernate. TBH our support for catalogs and schemas (especially in schema tooling) had been dubious.
Anyway, we tested your test against MySQL using default_catalog instead, and it works.


Top
 Profile  
 
 Post subject: Re: MySQL schema issue when migrating Hibernate 4 to 5
PostPosted: Fri Sep 30, 2016 2:37 am 
Newbie

Joined: Thu Sep 29, 2016 8:51 am
Posts: 2
Thank you very much!!!
That solved my problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.