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.  [ 1 post ] 
Author Message
 Post subject: PORTABLE SQL RANDOM FUNCTION ¿?
PostPosted: Sun Apr 08, 2007 3:49 pm 
Newbie

Joined: Sun Apr 08, 2007 3:28 pm
Posts: 1
Location: Mexico City
Hi !

I have a Table "Cancion" and I want to get from MySQL DB a list of random "Cancion" objects, then after searching a little bit in documentation and community help, I used the following code :

Code:
                IQuery sqlQuery = session.CreateSQLQuery("select {Cancion.*} from Cancion {Cancion} order by rand()", "Cancion", typeof(Cancion));
                sqlQuery.SetMaxResults(limit);
                cancion = (ArrayList)sqlQuery.List();


but I think this SQL is not portable for another DBMS (look here for random functions in other DBMS :http://www.petefreitag.com/item/466.cfm), Do you know another way to make it portable ?


Sergio López


Hibernate version: 1.0.4

Mapping documents:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="TuMama" assembly="TuMama">
  <class name="TuMama.Cancion" table="Cancion">
    <id name="IdCancion" column="id_cancion" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="Autor" column="autor" type="String" length="100"/>
    <property name="Path" column="path"  type="String" length="150"/>
    <property name="Titulo" column="titulo"  type="String" length="100"/>
  </class>
</hibernate-mapping>
[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.