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.