-->
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.  [ 14 posts ] 
Author Message
 Post subject: Human readable generated sql?
PostPosted: Fri Jun 24, 2005 4:53 am 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
Hi,
I was wondering if there is any work underway to make Hibernate generate human readable sql, that is, sql without all of those unecessary and weird names aliases for both fields and table names.

I understand having a unique way of addressing them is necessary to make the or-mapper work, but the current solution (at least with Hibernate 2.1.8, don't know about HIbernate 3) generated unecessary aliases that make the generated query harder to read...


Top
 Profile  
 
 Post subject: Re: Human readable generated sql?
PostPosted: Fri Jun 24, 2005 8:39 am 
Newbie

Joined: Tue Dec 16, 2003 12:02 pm
Posts: 14
Location: Geneva, Switzerland
Hello

have you tried using the opensource tool P6Spy http://www.p6spy.com/ ?

basically it is a sort of wrapper around your DB driver that logs every JDBC call, so you can not only read the query that's sent to your db , but also page through the result sets with actual replacement values.

The way I use it:
add the spy.jar to your classpath; then in your hibernate.properties, replace

hibernate.connection.driver_class org.postgresql.Driver

with

hibernate.connection.driver_class com.p6spy.engine.spy.P6SpyDriver

enter all JDBC connection details (driver, url, login, password etc...) in the spy.properties file provided by the tool.

et voila!

hope this helps,

Isabelle


aaime wrote:
Hi,
I was wondering if there is any work underway to make Hibernate generate human readable sql, that is, sql without all of those unecessary and weird names aliases for both fields and table names.

I understand having a unique way of addressing them is necessary to make the or-mapper work, but the current solution (at least with Hibernate 2.1.8, don't know about HIbernate 3) generated unecessary aliases that make the generated query harder to read...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 10:36 am 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
IPhan,
thank for your message. I already know about p6spy, but it does not help in having human readable sql.

What I'm complaining about is the SQL generated. Have a look:

select stateimpl4_.name as x0_0_, workflowmo5_.name as x1_0_, workflowmo3_.CREATION_DATE as x2_0_, workflowmo3_.ACTIVE as x3_0_, workflowmo3_.LAST_VERSION as x4_0_ from CL_WORKFLOW_STAGE workflowst0_ inner join CL_STAGE_ACTIVITY activities1_ on workflowst0_.ID=activities1_.WORKFLOW_STAGE_ID inner join CL_ACTIVITY treatmenta2_ on activities1_.ACTIVITY_ID=treatmenta2_.ID, CL_WORKFLOW_MODEL_VERSION workflowmo3_, JBPM_NODE stateimpl4_, CL_WORKFLOW_MODEL workflowmo5_ where workflowst0_.STATE_ID=stateimpl4_.id and workflowmo3_.WORKFLOW_MODEL_ID=workflowmo5_.ID and ((treatmenta2_.ID=144 )and(stateimpl4_.definition=workflowmo3_.DEFINITION_ID and workflowst0_.STATE_ID=stateimpl4_.id)) order by workflowmo5_.name , workflowmo3_.CREATION_DATE , stateimpl4_.name

Do you find it easy to read? I don't, and many of the aliases used are not really needed, especially for tables since their names are not repeated (in this query, at least).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 10:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate 3.1, set hibernate.format_sql=true.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 9:23 am 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
Christian,
thank you for your comment but... I cannot find any documentation on that parameter and I'm not using Hibernate 3.

So, a couple of questions:
* does format_sql avoid the generation of those ugly aliases? Format seems to imply just pretty prenting (maybe it's just my poor understanding of english)
* if so, would it be difficult to port it back to 2.1.8? (I'm not asking you to do it, just if it's possible and a time estimate)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 9:31 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The aliases are there for a reason, so No. Backporting is probably simple.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 10:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
in hibernate3 Dialect has getMaxAliasLength default set to 10. If you make that number higher the more you will get of the alias names making it more "human" but still unique. This of course requires that your db can handle alias names larger than 10...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 11:43 am 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
Sorry but I don't see the reason. Besides uniqueness, of course.
But for the fields it's not required if you are using positional access to the results, isn't it?
And for the tables, it's required only if there are two tables with the same name in the from clause, and in this particular case, and only for those tables, I have no objection to the use of aliases.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 11:45 am 
Newbie

Joined: Wed Mar 09, 2005 12:36 am
Posts: 12
This doesn't address your issue with alias names, but it helps get it relatively readable for me very quickly. I've used it often.

http://home.comcast.net/~danmeany/sqlformatter.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 11:50 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate doesn't use positional access. If you want to know more why aliases are generated, browse the source code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 11:51 am 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
As I stated in my first post, my problem is with the aliases. I can hand format the sql quite fast, what make the sql unreadable to me are the aliases.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 12:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
then increase the number in the Dialect and they will get more readable.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
aaime wrote:
Sorry but I don't see the reason. Besides uniqueness, of course.

Funny. You say that, then exactly state the reason ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
steve wrote:
aaime wrote:
Sorry but I don't see the reason. Besides uniqueness, of course.

Funny. You say that, then exactly state the reason ;)


:-)


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