-->
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: single valued field + join
PostPosted: Tue Nov 02, 2010 6:35 pm 
Newbie

Joined: Tue Nov 02, 2010 6:22 pm
Posts: 3
Hello,

I'm trying to execute a simple HQL query with JOIN:
Code:
SELECT title FROM Post p JOIN p.title title


where the Post entity is:
Code:
@Entity
public class Post
{
    private long id;
    private String title;

    public Post()
    {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    @Column
    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }
}


But I got an exception:
Quote:
java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:391)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3671)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3452)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3325)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:733)


Is it possible to create JOIN for a single valued property or this feature is unsupported? I use Hibernate 3.6.0. Thanks.


Top
 Profile  
 
 Post subject: Re: single valued field + join
PostPosted: Wed Nov 03, 2010 2:54 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Joining only works for related entities. You could do like this:

Code:
SELECT p.title FROM Post p


Top
 Profile  
 
 Post subject: Re: single valued field + join
PostPosted: Wed Nov 03, 2010 4:05 am 
Newbie

Joined: Tue Nov 02, 2010 6:22 pm
Posts: 3
nordborg wrote:
Joining only works for related entities. You could do like this:

Code:
SELECT p.title FROM Post p


nordborg, thanks for your answer! Actually, "SELECT p.title FROM Post p" works fine. It is one of possible solutions.

But I still have a question: is query "SELECT title FROM Post p JOIN p.title title" syntactically incorrect?


Top
 Profile  
 
 Post subject: Re: single valued field + join
PostPosted: Wed Nov 03, 2010 4:42 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The syntax is correct, but it will only work if 'title' is another entity, not if it is a property.


Top
 Profile  
 
 Post subject: Re: single valued field + join
PostPosted: Wed Nov 03, 2010 4:52 am 
Newbie

Joined: Tue Nov 02, 2010 6:22 pm
Posts: 3
nordborg wrote:
The syntax is correct, but it will only work if 'title' is another entity, not if it is a property.


I get it! Thanks!


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.