-->
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: Overriding generated SQL
PostPosted: Mon Nov 01, 2004 5:19 pm 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Hibernate version: 3

I was reading about new feature of overriding generated SQL by handwritten SQL embedded in the mapping document in blog "Using Hibernate3 as a JDBC framework".

I stopped at:
Code:
<class name="Person" lazy="true">
    <id name="id" unsaved-value="0">
        <generator class="increment"/>
    </id>   
    <property name="name" not-null="true"/>   
    <loader query-ref="person"/>   
    <sql-insert>INSERT INTO PERSON (NAME, ID) VALUES ( UPPER(?), ? )</sql-insert>
    <sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE ID=?</sql-update>
    <sql-delete>DELETE FROM PERSON WHERE ID=?</sql-delete>
</class>

<sql-query name="person">
    <return alias="p" class="Person" lock-mode="upgrade"/>
SELECT NAME AS {p.name}, ID AS {p.id} FROM PERSON WHERE ID=? FOR UPDATE
Code:
</sql-query>


If I am querying "person" by name or by any other property (not id), how can I override those kind of queries?

How is this solved hypothetically?

Thanks a lot,

Marko


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 4:06 pm 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Please!

Marko


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 4:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use createSQLQuery of course


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 5:08 pm 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Thank you. But that is not new.

I thought it can be done in mapping, so it would look for programmer like ordinary class with ordinary mapping and he could query data by any property he wanted.

Thank you for your help again.

Marko


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.