-->
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: selecting a Set and field from an entity in one query.
PostPosted: Sun May 24, 2009 2:28 am 
Newbie

Joined: Sun May 24, 2009 2:12 am
Posts: 1
I'm having an issue selecting a Set field with any other field from an entity. I get bad sql from hibernate. I've tried this on both mysql and oracle, but get the same results. It includes a field with no name in the sql.

My setup is something like this.

Code:
@Entity
public class Task {

   @ManyToMany
   private Set<Environment> environments = new HashSet<Environment>();
 
   @Id
   @GeneratedValue
   private Long id;
}

@Entity
public class Environment {
   @Id
   @Generatedvalue
   private Long id;

   <other fields>
}


This HQL works fine

Code:
SELECT task.environments FROM Task task

But this HQL fails.

Code:
SELECT task.id, task.environments FROM Task task

It generates SQL like this.

Code:
    select
        task0_.id as col_0_0_,
        . as col_1_0_,
        <other Environment fields>
    from
        Task task0_
    inner join
        Task_Environment environmen1_
            on task0_.id=environmen1_.Task_id
    inner join
        Environment environmen2_
            on environmen1_.environments_id=environmen2_.id

notice the part
Code:
   . as col_1_0_,

that's invalid sql.

am I doing something wrong?


p.s. incidentally I've tried this with multiple sets, with sets inside a type-safe object instantiation, and several other ways. It only fails when a non-collection is included in the mix. selecting multiple sets at the same time works fine.


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.