GroypBy.list() returns only first expression of ContructorExpressions #117

Closed
lallafa opened this Issue Mar 18, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@lallafa

lallafa commented Mar 18, 2012

this query:

        Map<Long, List<Pair<Long, String>>> map = new HibernateQuery(session)
            .from(author)
            .join(author.books, book)
            .transform(GroupBy
                .groupBy(author.id)
                .as(GroupBy.list(QPair.create(book.id, book.title))));

returns a Map that contains List<Long> (with book.id as elements) instead of List<Pair<Long, String>>

Tested with querydsl 2.3.2 and hibernate 3.6.9

@lallafa

This comment has been minimized.

Show comment
Hide comment
@lallafa

lallafa Mar 18, 2012

Test sources:

@Entity
public class Author implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

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

    @OneToMany(mappedBy="author")
    @OrderBy("title")
    private Set<Book> books;
    public Set<Book> getBooks() { return books; }
    public void setBooks(Set<Book> books) { this.books = books; }
}

@Entity
public class Book implements Serializable {

    @Id  @GeneratedValue
    private Long id;
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

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

    @ManyToOne
    @JoinColumn(name="AUTHOR_ID")
    private Author author;
    public Author getAuthor() { return author; }
    public void setAuthor(Author author) { this.author = author; }
}


    @Test
    @Transactional(readOnly=true)
    public void testSomeMethod0() {
        Session session = sessionFactory.getCurrentSession();

        QAuthor author = QAuthor.author;
        QBook book = QBook.book;

        Map<Long, List<Pair<Long, String>>> map = new HibernateQuery(session)
            .from(author)
            .join(author.books, book)
            .transform(GroupBy
                .groupBy(author.id)
                .as(GroupBy.list(QPair.create(book.id, book.title))));

        for (Entry<Long, List<Pair<Long, String>>> entry : map.entrySet()) {
            System.out.println("author = " + entry.getKey());

            for (Object pair : entry.getValue()) {
                System.out.println("  book = " + pair);
            }
        }
    }

lallafa commented Mar 18, 2012

Test sources:

@Entity
public class Author implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

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

    @OneToMany(mappedBy="author")
    @OrderBy("title")
    private Set<Book> books;
    public Set<Book> getBooks() { return books; }
    public void setBooks(Set<Book> books) { this.books = books; }
}

@Entity
public class Book implements Serializable {

    @Id  @GeneratedValue
    private Long id;
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

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

    @ManyToOne
    @JoinColumn(name="AUTHOR_ID")
    private Author author;
    public Author getAuthor() { return author; }
    public void setAuthor(Author author) { this.author = author; }
}


    @Test
    @Transactional(readOnly=true)
    public void testSomeMethod0() {
        Session session = sessionFactory.getCurrentSession();

        QAuthor author = QAuthor.author;
        QBook book = QBook.book;

        Map<Long, List<Pair<Long, String>>> map = new HibernateQuery(session)
            .from(author)
            .join(author.books, book)
            .transform(GroupBy
                .groupBy(author.id)
                .as(GroupBy.list(QPair.create(book.id, book.title))));

        for (Entry<Long, List<Pair<Long, String>>> entry : map.entrySet()) {
            System.out.println("author = " + entry.getKey());

            for (Object pair : entry.getValue()) {
                System.out.println("  book = " + pair);
            }
        }
    }
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 20, 2012

Member

Released in 2.5.0

Member

timowest commented Apr 20, 2012

Released in 2.5.0

@timowest timowest closed this Apr 20, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment