0

I use Hibernate to get data from MySQL 5.5.28 database, this is query from Hibernate with org.hibernate.exception.SQLGrammarException error:

Hibernate: 
select user0_.uid as uid1_0_0_, user0_.motorcycle as motorcyc2_0_0_, user0_.password as password3_0_0_, user0_.username as username4_0_0_
from db-jade-na-zlot.users user0_ 
where user0_.uid=1;

i try to check this in phpMyAdmin and this query works fine:

select user0_.uid as uid1_0_0_, user0_.motorcycle as motorcyc2_0_0_, user0_.password as password3_0_0_, user0_.username as username4_0_0_
from users user0_ 
where user0_.uid=1;

i checked 5 times database name in hibernate.cfg.xml, but it's ok. What i'm doing wrong?

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>

<session-factory>
    <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/db-jade-na-zlot</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">vertrigo</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <mapping class="pl.jadenazlot.model.User"></mapping>
</session-factory>

error:

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-jade-na-zlot.users user0_ where user0_.uid=1' at line 1
3
  • can you post the entire stacktrace, also are you specifying a specific HibernateDialect, and is that dialect up to date? Commented Feb 28, 2014 at 7:24
  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-jade-na-zlot.users user0_ where user0_.uid=1' at line 1 Commented Feb 28, 2014 at 7:26
  • can you update your answer and include your hibernate config Commented Feb 28, 2014 at 7:35

1 Answer 1

1

is db-jade-na-zlot a valid schema/database name?
Probably you need to thick it putting

``

around this name to teach Hibernate to treat as identifier and quoting it into generated SQL

Sign up to request clarification or add additional context in comments.

4 Comments

my-db was temporary name for post, correct is db-jade-na-zlot.
i tried in phpMyAdmin query with " FROM 'db-jade-na-zlot'.'users' ... ", but still is syntax error.
backthick is the rdbms independant identifier quote char for hibernate; for MySQL (looking at dialect) the quote character is the backthick itself (but this is just a coincidence)
helps change db-jade-na-zlot to dbjadenazlot, thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.