-->
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.  [ 5 posts ] 
Author Message
 Post subject: mapping on result fonctions
PostPosted: Fri Sep 22, 2006 4:30 am 
Newbie

Joined: Fri Sep 22, 2006 4:17 am
Posts: 10
Hibernate version:3.1.3

Name and version of the database you are using:Oracle 10g

Hi,

I would like to know if it is possible and how to map a property to a sql function.

I am using Oracle with EST and it provides two functions
ST_ASTEXT and ST_POLYFROMTEXT. The first one converts the stored data of a column as a text and the second one does the reverse function.

My POJO has a property "shape" as String.

I tried to use an interceptor which on the onPrepareStatement method replace the column with the function for the SELECT query. This actually runs well.

I tried to do the same operation for an update which replace the "?" of SHAPE by "select ST_POLYFROMTEXT('?',1) from dual.

I encounter this error:
2006-09-22 10:06:07,031|ERROR|Index de colonne non valide


thanks in advance,


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 24, 2006 7:50 pm 
Newbie

Joined: Mon Aug 29, 2005 1:14 am
Posts: 10
I'm no Hibernate expert, and I haven't tested this. However, I think the Hibernate docs, section 16.4, may explain how to do what you want (and you could get rid of the interceptor, too).

Quoting from 16.4:


Quote:
Hibernate3 can use custom SQL statements for create, update, and delete operations. The class and collection persisters in Hibernate already contain a set of configuration time generated strings (insertsql, deletesql, updatesql etc.). The mapping tags <sql-insert>, <sql-delete>, and <sql-update> override these strings:


Code:
<class name="Person">
    <id name="id">
        <generator class="increment"/>
    </id>
    <property name="name" not-null="true"/>
    <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>


Also, since your update sql uses a subquery, shouldn't in be in parentheses?
"(select ST_POLYFROMTEXT('?',1) from dual)"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 5:04 am 
Newbie

Joined: Fri Sep 22, 2006 4:17 am
Posts: 10
Ok , thanks I will try.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 5:17 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
Not sure but can we use formula to achive this ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 4:19 am 
Newbie

Joined: Fri Sep 22, 2006 4:17 am
Posts: 10
Hi,
I use the element <loader> in my mapping to call a sql-query that does a ST_ASTEXT(SHAPE).

My mapping is like that:
Code:
  <class table="TMYTABLE" name="MyTable" lazy="false">
    <id column="idTable" name="idTable" type="string">
     [...]
    </id>
    <property column="shape" name="shape" type="string"/>
    <property column="objectId" name="objectId" type="string"/>
   
    <loader query-ref="loadMyTable"/>
  </class>


<sql-query name="loadMyTable">
    <return alias="myTable" class="MyTable" lock-mode="none"/>
   

    SELECT ST_ASTEXT(SHAPE)     AS {myTable.shape},
           OBJECTID             AS {myTable.objectId},
           IDTABLE AS {myTable.idTable}
    FROM TMYTABLE WHERE IDTABLE =?
  </sql-query>


My problem is when I try to get my myTable pojo by objectId, the sql query retrieve SHAPE and not ST_ASTEXT(SHAPE).

The code is:
Code:
       return (List) getHibernateTemplate().execute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException  {
               
                Query query = session.createQuery("FROM MyTable myTable WHERE MyTable.idObject= :idObject");
                query.setParameter("idObject", idObject, Hibernate.STRING);
                return query.list();
            }
        });       


Does anyone know how to retrieve correctly my object?

Actually I'll prefere not to write the all select statement as this mapping is a sample of the real mapping and there are more columns and relation between tables. There is a table TPARENT that have a one-to-many relation with this table. and this table has a many-to-one relation with another table which has also a "SHAPE" column.

thanks in advance


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