-->
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: can i call database function in annotation @Where ?
PostPosted: Fri Apr 13, 2007 1:35 am 
Newbie

Joined: Fri Apr 13, 2007 12:50 am
Posts: 3
Code:
@Where(clause = "enddate >= today")

Annotation is on the getter, enddate is the field of my table, today is the Informix DB function returns current day.

Exception - "SQL Error: -217, SQLState: Column (today) not found in any table in the query (or SLV is undefined)."
That is Informix DB considers today as a column but today is its function.
How solve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 2:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
what is the SQL query generated?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 12:19 am 
Newbie

Joined: Fri Apr 13, 2007 12:50 am
Posts: 3
emmanuel wrote:
what is the SQL query generated?


...Well, I have j2ee application: Informix DB - JBoss 4.0.4 AS - Swing Cilent, EJB3. SQL query is in class below:

Code:
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "my_table")
public class MyQuery implements Serializable
{
    private Date endDate;
    private String name;
    private MyQuery parId;
    private Set<MyQuery> childs;

    public MyQuery()
    {
        childs = new HashSet<MyQuery>();
    }

    @ManyToOne
    @JoinColumn(name = "par_id")
    public MyQuery getParId()
    {
        return parId;
    }

    public void setParId(MyQuery parId)
    {
        this.parId = parId;
    }

    @Column(name = "full_name")
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Date getEndDate()
    {
        return endDate;
    }

    public void setEndDate(Date endDate)
    {
        this.endDate = endDate;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "parId")
    @OrderBy("code ASC")
    @Where(clause = "enddate >= today")
    public Set<MyQuery> getChilds()
    {
        return childs;
    }

    public void setChilds(Set<MyQuery> childs)
    {
        this.childs = childs;
    }
}


I need to get the field Set<MyQuery> childs where "enddate >= today".
I can get it if I create DB function(my_function) returns today in the following way:

Code:
@Where(clause = "enddate >= my_function()")


In this case Hibernate + Informix recognized my_function() as a function and executed that SQL query.

How to call system DB function in annotation?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 10:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Anf if you run the SQL query (with today) directly, it works? I think it fails too.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 12:34 am 
Newbie

Joined: Fri Apr 13, 2007 12:50 am
Posts: 3
emmanuel wrote:
Anf if you run the SQL query (with today) directly, it works? I think it fails too.


SQL query with today works:
Code:
select full_name, enddate from my_table where enddate >= today

About today function: http://www.inquiry.com/techtips/info_pro/10min/10min1000/10min1000-2.asp

...In general I solved this problem without annotation @Where.
Thanks... and if You have any good idea about "How to call system DB function in annotation @Where" please write me.


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.