Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

@lallafa
Copy link

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
Copy link
Author

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
Copy link
Member

Released in 2.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants