-->
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.  [ 4 posts ] 
Author Message
 Post subject: Erroneous SQL query composed by Hibernate ?
PostPosted: Fri Jun 28, 2013 10:42 am 
Newbie

Joined: Fri Jun 28, 2013 10:19 am
Posts: 3
Hi,

I have a MySql server running multiples databases. I use the following connection URL to connect to my databases :

Code:
jdbc:mysql://127.0.0.1/


Hibernate seemed to perfectly work until I tried to add a row in one of my tables. I looked at the SQL query generated by Hibernate and it's missing the catalog prefix :

Code:
>16:29:46 [INFO] Hibernate: select max(id) from prohibited_item_log_entry
>16:29:46 [WARN] SQL Error: 1046, SQLState: 3D000
16:29:46 [ERROR] No database selected


Hibernate is trying to get the future id of the row but it doesn't tell in which database is located "prohibited_item_log_entry", this raises a SQL error. The generated query should be :
Code:
select max(id) from ftm_prohibition.prohibited_item_log_entry

"ftm_prohibition" is the database where "prohibited_item_log_entry" is located.

For all other queries, Hibernate use the "from [catalog].[table_name]" syntax, and everything works like a charm :

Code:
>16:29:41 [INFO] Hibernate: select prohibited0_.id as id1_6_, prohibited0_.version as version2_6_, prohibited0_.filter as filter6_6_ from ftm_prohibition.prohibited_item prohibited0_


How can I fix this problem ?


Top
 Profile  
 
 Post subject: Re: Erroneous SQL query composed by Hibernate ?
PostPosted: Sat Jun 29, 2013 10:11 pm 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
Have you tried "jdbc:mysql://127.0.0.1/ftm_prohibition" instead?

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


Top
 Profile  
 
 Post subject: Re: Erroneous SQL query composed by Hibernate ?
PostPosted: Sun Jun 30, 2013 2:39 am 
Newbie

Joined: Fri Jun 28, 2013 10:19 am
Posts: 3
saltnlight5 wrote:
Have you tried "jdbc:mysql://127.0.0.1/ftm_prohibition" instead?

Yes I dis. It will work for this database only. But if I try to create a record into the table "foo" in the database "bar", hibernate will try to execute this query :

Quote:
select max(id) from ftm_prohibition.foo


Actually, Hibernate ignores the "catalog" attribute when I try to create a row, it uses the database provided in the url instead. I don't really understand why...


Top
 Profile  
 
 Post subject: Re: Erroneous SQL query composed by Hibernate ?
PostPosted: Mon Jul 01, 2013 9:33 am 
Newbie

Joined: Fri Jun 28, 2013 10:19 am
Posts: 3
Problem solved!

I had to specify the schema into the generators :

Code:
           
<generator class="increment">
    <param name="catalog">ftm_prohibition</param>
</generator>


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