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

Comments

Projects
None yet
2 participants
@daniel-frank

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 31, 2013

Member

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

Member

timowest commented Jul 31, 2013

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

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank 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))))

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 31, 2013

Member

Did you try to alias the list expression?

Member

timowest commented Jul 31, 2013

Did you try to alias the list expression?

@ghost ghost assigned timowest Jul 31, 2013

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Jul 31, 2013

Tried right now with the exact same error.

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 2, 2013

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Aug 5, 2013

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

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

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 5, 2013

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank 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.

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 7, 2013

Member

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

Member

timowest commented Aug 7, 2013

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

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank 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.

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 9, 2013

Member

Could you try again with the latest SNAPSHOT?

Member

timowest commented Aug 9, 2013

Could you try again with the latest SNAPSHOT?

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Aug 9, 2013

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

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

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 9, 2013

Member

The latest 3.2.3.BUILD-SNAPSHOT version should work.

Member

timowest commented Aug 9, 2013

The latest 3.2.3.BUILD-SNAPSHOT version should work.

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Aug 10, 2013

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

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

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 10, 2013

Member

Do you mean aliasing the list expression causes still problems?

Member

timowest commented Aug 10, 2013

Do you mean aliasing the list expression causes still problems?

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Aug 10, 2013

Yup, same problem.

Yup, same problem.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Aug 27, 2013

Member

Released in 3.2.3

Member

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