-->
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.  [ 6 posts ] 
Author Message
 Post subject: createSQLQuery() and update, table names
PostPosted: Fri Dec 26, 2003 1:12 am 
Beginner
Beginner

Joined: Mon Sep 15, 2003 6:55 pm
Posts: 29
1. Is it at all possible to do an "update" using the same syntax as you would use with session.createSQLQuery()?

2. The examples in the documentation say things like
"SELECT {cat.*} FROM CAT AS {cat} WHERE ROWNUM<10"
Notice that the name of the table, "CAT", is hard coded into the query. Is there a way to just give just the class name, and let hibernate figure out which table it is?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 26, 2003 6:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
1. No (at least not at the moment....make a JIRA entry if you reallly want it ... and with arguments on why you don't just use the connection() directly ;) ...but it really is hard to make that feature cleanly, so i don't think it will pop up anytime soon ;)

2. Well - if you just need that, why not just use hql directly ? ...but if you can come up with a good simple syntax for it then we *might* consider it.
Secondly, i can see your sql query uses rownum to select the first 10 parts...you do know that that is what hibernate does when using setMaxResults() etc. when using oracle ? (so, if that is what you are doing - then just use hql instead, it's more portable ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 27, 2003 1:32 am 
Beginner
Beginner

Joined: Mon Sep 15, 2003 6:55 pm
Posts: 29
What I'm actually writing is much more complex than what I put - I didn't want to add unecessary complexity to my post. These "sql queries" are supposed to allow you to refer to your objects without having to remember the column names for their properties, so I find it very strange that you have to remember the table name for the class to do a query.

I appreciate your advice, but the query I posted is directly from the hibernate documentation, I just need a simple example.

Intuitively, "SELECT {cat.*} FROM {cat} AS {cat} WHERE ROWNUM<10" seems like the best syntax to me (treat {} stuff differently when it's between FROM and WHERE.

However, if that doesn't work for technical reasons, how about:
"SELECT {cat.*} FROM {table:cat} AS {cat} WHERE ROWNUM<10"?


Top
 Profile  
 
 Post subject: PS
PostPosted: Sat Dec 27, 2003 2:06 am 
Beginner
Beginner

Joined: Mon Sep 15, 2003 6:55 pm
Posts: 29
I did post the "sql update" issue to JIRA (http://opensource.atlassian.com/project ... key=HB-581) - although as I explain there, I sorta thought that implementing it would be rather easy and just as clean as the syntax currently used for createSQLQuery().


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 27, 2003 6:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Current the createSQLQuery() "parser" is really really dumb and thus very simple ;), and hence i would prefer the {table:xxx} stuff....but it get's nasty (but not unsolvable) when we need to handle <joined-subclass> which span's multiple tables! (then the syntax would be something like {table:(Subclass)superclassalias} and then it's get's LOOONG ;)

...i follow your arguments, so add it to the jira as a seperate issue.

The sql update thingy is MESSY since what you are actually asking for is "bulk-update", which Hibernate (as it is an ORM) have a hard time fullfilling because it respect the lifecycle of objects - and thus need to reload objects etc.

IF this should be provided currently, it would be a small helper-class that exposes the sql alias replacement stuff....but that ain't nice ;)
But now it is in the JIRA and won't be forgotten (without a reason anyway ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 28, 2003 12:53 am 
Beginner
Beginner

Joined: Mon Sep 15, 2003 6:55 pm
Posts: 29
I posted the "hard-coded table name in sql query" issue to JIRA:
http://opensource.atlassian.com/project ... key=HB-585


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