-->
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.  [ 3 posts ] 
Author Message
 Post subject: Name of the database column in HQL query?
PostPosted: Mon Mar 29, 2004 6:24 pm 
Newbie

Joined: Wed Oct 22, 2003 11:52 am
Posts: 3
Location: Qu
This code works perfectly!!

Code:
Query query = session.createQuery("from Evenement where CODE_INITIATEUR_CTRL = :initiateur");
query.setString("initiateur", initiateur);
List resultat = query.list();


My problem is that am using the name of the column in my database, this is bad! Usually I use the name of the attribute in my Java object.

I want this code to work. It would be a lot better I think!!
Code:
Query query = session.createQuery("from Evenement where initiateur = :initiateur");
query.setString("initiateur", initiateur);
List resultat = query.list();


I have this Exception when running this code.
java.sql.SQLException: ORA-00904: "INITIATEUR": invalid identifier



Here is my Class and Mapping. (Simplified to expose the problem)
Oracle9, Hibernate 2.1.2

Code:
public class Evenement implements Serializable{
    private Long id;
    private String initiateur;

    public Evenement() {}

    public Long getId() {
        return id;
    }
   
    public void setId(Long id) {
        this.id = id;
    }

    public String getInitiateur() {
         return initiateur;
    }

    public void setInitiateur(String string) {
        initiateur = string;
    }
}



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping schema="vip">
<class name="com.lq.infrastructure.services.journalisation.evenement.Evenement" table="T_EVENEMENT">
       <id name="id" column="ID_EVENEMENT">
            <generator class="sequence">
              <param name="sequence">sq_evenement</param>
            </generator>
       </id>
       <property name="initiateur" column="CODE_INITIATEUR_CTRL" not-null="true"/>
    </class>
</hibernate-mapping>




Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 1:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Change
Quote:
Query query = session.createQuery("from Evenement where initiateur = :initiateur");


to

Code:
Query query = session.createQuery("from Evenement as e where e.initiateur = :initiateur");


'e' is the alias for the object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 11:34 am 
Newbie

Joined: Wed Oct 22, 2003 11:52 am
Posts: 3
Location: Qu
Thank you. It works!


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