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

ArrayIndexOutOfBoundsException when transforms results using alias #465

Closed
daniel-frank opened this issue Jul 31, 2013 · 17 comments
Closed

ArrayIndexOutOfBoundsException when transforms results using alias #465

daniel-frank opened this issue Jul 31, 2013 · 17 comments
Assignees
Milestone

Comments

@daniel-frank
Copy link

@daniel-frank daniel-frank commented Jul 31, 2013

Using this:

final events = new SimplePath<SimpleEvent>(SimpleEvent, 'events')
final query = (...)
final data = query.transform(groupBy(e.id).as(constructor(EmployeeDTO, e.id, e.name, list(constructor(SimpleEvent, v.type, v.description, v.value).as(events)))))

I get a:

java.lang.ArrayIndexOutOfBoundsException: 2
    at com.mysema.query.group.GroupImpl.add(GroupImpl.java:60)
    at com.mysema.query.group.GroupBy.transform(GroupBy.java:168)
    at com.mysema.query.group.GroupBy.transform(GroupBy.java:38)
    at com.mysema.query.support.ProjectableQuery.transform(ProjectableQuery.java:80)

Same projecting direct to a Group:

final events = new SimplePath<SimpleEvent>(SimpleEvent, 'events')
final query = (...)
final groupedById = query.transform(groupBy(e.id).as(e.name, list(constructor(SimpleEvent, v.type, v.description, v.value).as(events))))

If I remove the alias like this:

final query = (...)
final groupedById = query.transform(groupBy(e.id).as(e.name, list(constructor(SimpleEvent, v.type, v.description, v.value))))

All works fine, but when I try to project manually to EmployeeDTO I have to use a complete ConstructorExpressions:

final data = groupedById.values().collect {g -> new EmployeeDTO(id: g.getOne(e.id),
                                                                name: g.getOne(e.name),
                                                                events: g.getList(constructor(SimpleEvent, v.type, v.description, v.value)))
}

Am I doing something wrong? Or its a bug?

@timowest
Copy link
Member

@timowest timowest commented Jul 31, 2013

Could you use Java in the code examples? Otherwise it is a bit difficult to follow.

@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Jul 31, 2013

Sure. Sorry.

1:

SimplePath<SimpleEvent> events = new SimplePath<SimpleEvent>(SimpleEvent, 'events');
JPAQuery query = (...);
Map<Integer, EmployeeDTO> data = query.transform(groupBy(e.id).as(constructor(EmployeeDTO.class, e.id, e.name, list(constructor(SimpleEvent.class, v.type, v.description, v.value).as(events)))));

2:

SimplePath<SimpleEvent> events = new SimplePath<SimpleEvent>(SimpleEvent, 'events');
JPAQuery query = (...);
Map<Integer, Group> groupedById = query.transform(groupBy(e.id).as(e.name, list(constructor(SimpleEvent.class, v.type, v.description, v.value).as(events))))

3:

JPAQuery query = (...);
Map<Integer, Group> = query.transform(groupBy(e.id).as(e.name, list(constructor(SimpleEvent.class, v.type, v.description, v.value))))
@timowest
Copy link
Member

@timowest timowest commented Jul 31, 2013

Did you try to alias the list expression?

@ghost ghost assigned timowest Jul 31, 2013
@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Jul 31, 2013

Tried right now with the exact same error.

timowest added a commit that referenced this issue Aug 1, 2013
timowest added a commit that referenced this issue Aug 2, 2013
@timowest
Copy link
Member

@timowest timowest commented Aug 2, 2013

Could you try again with the latest SNAPSHOT from here https://oss.sonatype.org/content/repositories/snapshots/

The alias is now handled better in the transformation

@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Aug 5, 2013

Same error running with 3.2.3.BUILD-SNAPSHOT, aliasing both construct or list expression.

@timowest
Copy link
Member

@timowest timowest commented Aug 5, 2013

How does the underlying JPQL query look like? It looks like for some reason it doesn't have the same amount of columns as the GroupBy transformer expects.

@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Aug 6, 2013

Generated select without alias:

SELECT t0.matricula, t1.nome, t0.matricula, t1.cpf, t2.valor, t3.codigo, t3.descricao, t4.valor, t3.valor, t5.tipo_evento

With alias:

SELECT t0.matricula, t1.tipo_evento

It really doesn't have the same amount of columns.

@timowest
Copy link
Member

@timowest timowest commented Aug 7, 2013

Could you provide the full queries? Otherwise I can only speculate what the t* aliases refer to.

@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Aug 8, 2013

Generated JPQL query without alias:

select trabalhadorCargo.matricula, trabalhadorCargo.trabalhador.nome, calculoFormula.descricao, calculoVariavel.valor, calculoFormula.valor, calculoEvento.tipoEvento
from CalculoFormula calculoFormula
  inner join calculoFormula.trabalhadorCargo as trabalhadorCargo
  inner join calculoFormula.calculoEvento as calculoEvento
  left join calculoFormula.variaveis as calculoVariavel on calculoFormula.referenciaFormula = calculoVariavel.chave
where calculoFormula.calculoReferencia = ?1 and trabalhadorCargo.categoria in ?2 and calculoFormula.principal = ?3 and calculoFormula.valor > ?4 and calculoEvento.subFormula = ?5
order by trabalhadorCargo.id asc, calculoEvento.fixo asc, calculoEvento.constante asc, calculoEvento.codigo asc

With alias:

select trabalhadorCargo.matricula, trabalhadorCargo.trabalhador.nome, calculoFormula.descricao, calculoVariavel.valor, calculoFormula.valor, calculoEvento.tipoEvento as eventos
from CalculoFormula calculoFormula
  inner join calculoFormula.trabalhadorCargo as trabalhadorCargo
  inner join calculoFormula.calculoEvento as calculoEvento
  left join calculoFormula.variaveis as calculoVariavel on calculoFormula.referenciaFormula = calculoVariavel.chave
where calculoFormula.calculoReferencia = ?1 and trabalhadorCargo.categoria in ?2 and calculoFormula.principal = ?3 and calculoFormula.valor > ?4 and calculoEvento.subFormula = ?5
order by trabalhadorCargo.id asc, calculoEvento.fixo asc, calculoEvento.constante asc, calculoEvento.codigo asc

The eventos alias is put in for calculoEvento.tipoEvento only, but its really a construct alias inside a list expression.

@timowest
Copy link
Member

@timowest timowest commented Aug 9, 2013

Could you try again with the latest SNAPSHOT?

@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Aug 9, 2013

Sure, waiting for the next SNAPSHOT. (3.2.3.BUILD-SNAPSHOT is the last until now)

@timowest
Copy link
Member

@timowest timowest commented Aug 9, 2013

The latest 3.2.3.BUILD-SNAPSHOT version should work.

@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Aug 10, 2013

Aliasing the constructor expression now works like a charm, however the error with list expression still remains.

@timowest
Copy link
Member

@timowest timowest commented Aug 10, 2013

Do you mean aliasing the list expression causes still problems?

@daniel-frank
Copy link
Author

@daniel-frank daniel-frank commented Aug 10, 2013

Yup, same problem.

@timowest
Copy link
Member

@timowest timowest commented Aug 27, 2013

Released in 3.2.3

@timowest timowest closed this Aug 27, 2013
@timowest timowest added this to the 3.2.3 milestone Apr 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants