-->
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.  [ 9 posts ] 
Author Message
 Post subject: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 9:03 am 
Newbie

Joined: Thu Mar 22, 2007 12:25 pm
Posts: 11
Hi guys,

I am trying to reverse-engineer a local MySQL database with Hibernate tools (v3.4.0.v20110215-1252-H31-GA) and I'm experiencing strange issues while creating the reveng.xml file via the wizard.

First of all, I've created the following hibernate.cfg file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">xxxxx</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db_name</property>
        <property name="hibernate.connection.username">xxxxx</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>


Next, I've created and established a connection to the database via the MySQL-connector. Pinging and reading the DB through the 'Database Development' view succeeds. This newly created DB connection is also selected in the console configuration for Hibernate, as is the hibernate.cfg.xml.

But when I create a reveng.xml file via the wizard and press the 'Refresh' button in the view, the following exception occurs:
Code:
org.hibernate.exception.SQLGrammarException: Error while reading column meta data for db_name.gs
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getColumns(JDBCMetaDataDialect.java:146)
at org.hibernate.cfg.reveng.JDBCReader.processBasicColumns(JDBCReader.java:578)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:85)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:117)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:72)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:106)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:63)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user ''@'%' for column 'customerid' in table 'customer'
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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2569)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1510)
at com.mysql.jdbc.DatabaseMetaData$2.forEach(DatabaseMetaData.java:2501)
at com.mysql.jdbc.IterateBlock.doForAll(IterateBlock.java:51)
at com.mysql.jdbc.DatabaseMetaData.getColumns(DatabaseMetaData.java:2375)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getColumns(JDBCMetaDataDialect.java:124)
... 10 more


It seems to me that Hibernate is not able to replace parts of the query with my specified credentials:
Code:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user ''@'%' for column 'customerid' in table 'customer'


Is this a bug or am I missing something here?

Thanks for your help,
Proph.


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 9:16 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
The message meens that the user your using to login to mysql does not have permission to execute SELECT on the customer table.


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 9:21 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
Dmitry Geraskov wrote:
The message meens that the user your using to login to mysql does not have permission to execute SELECT on the customer table.

Sorry, seems you understood this.

Did you try to execute this quesry with your credentials manually?


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 9:29 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
To make sure:
1. You create Connection Profile and connection works well (you can see database structure in Data Source Explorer view)
2. In your Console Configuration you switched to JPA type and select the connection profile as Database Connection
3. In Hibernate Configurations view you can expand the Console Configuration->Database item and see database structure?


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 9:59 am 
Newbie

Joined: Thu Mar 22, 2007 12:25 pm
Posts: 11
Thanks for your quick replies.

It seems that I have selected the 'Core' type option in the reveng launch configuration. Is JPA really needed when reverse-engineering a database to Java POJOs?

Regarding your other questions above:
Dmitry Geraskov wrote:
1. You create Connection Profile and connection works well (you can see database structure in Data Source Explorer view)

yes

Dmitry Geraskov wrote:
3. In Hibernate Configurations view you can expand the Console Configuration->Database item and see database structure?


yes I do

Dmitry Geraskov wrote:
Did you try to execute this quesry with your credentials manually?


Yes, this works fine.


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 10:02 am 
Newbie

Joined: Thu Mar 22, 2007 12:25 pm
Posts: 11
Dmitry Geraskov wrote:
3. In Hibernate Configurations view you can expand the Console Configuration->Database item and see database structure?


Oh sorry, my mistake. I get the above mentioned exception when expanding the Database item. But viewing the DB structure works with the 'Database Development' view.


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 5:15 pm 
Newbie

Joined: Thu Mar 22, 2007 12:25 pm
Posts: 11
but still ... the issue is not resolved yet. Any other hints regarding the problem?


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Fri Jun 17, 2011 5:16 pm 
Newbie

Joined: Thu Mar 22, 2007 12:25 pm
Posts: 11
but still ... the issue is not resolved yet. Any other hints regarding the problem?


Top
 Profile  
 
 Post subject: Re: SQLGrammarException when using Hibernate Tools with Helios
PostPosted: Mon Jun 20, 2011 4:58 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
Yes, JPA type should be selected to use Connection Profile.
Hibernate will use user/password which you provided in the selected connection profile to connect to DB(if they are not empty).
The problem with exploring DB structure in the Config view means that this is not reveng problem. Hibernate just can't get database structure at all.
And are you sure that now exception is the same?

Did you try to explore table columns in Datasource Explorer view or only tables?


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