I have a problem when using Projection and ResultTransformer on a criteria.
I have an entity which looks like this:
Code:
@Entity
....
public class FavoriteEntityImpl implements FavoriteEntity, Serializable {
@Id
@Column(name = "ID", nullable = false, columnDefinition = "char(36)")
private String ID;
@Column(name = "FAV_NAME", nullable = false, length = 255)
@Field(index = Index.TOKENIZED, store = Store.YES)
private String favoriteName;
@ElementCollection(fetch = FetchType.LAZY)
@JoinTable(name = "FAV_FavoriteProperties", joinColumns = @JoinColumn(name = "ID"))
@MapKeyColumn(name = "propertyName", nullable = false)
@Column(name = "propertyValue", nullable = false)
@Cascade(value = org.hibernate.annotations.CascadeType.ALL)
@Field(index = Index.TOKENIZED, store = Store.YES)
@FieldBridge(impl = MapFieldBridge.class)
private Map<String, String> properties;
....
This entity has some properties: ID, favoriteName and properties (a Map).
When I want to get all Entities I would like to transform the result into a DTO-Class which look like this:
Code:
public class FavoriteImpl implements Favorite {
private String id;
private String favoriteName;
private Map<String, String> properties;
// getter, setter
So, I set projections and the AliasToBeanResultTransformer:
Code:
Criteria crit = getCurrentSession().createCriteria(FavoriteEntityImpl.class)
.add(/*Restrictions...*/)
.setProjection(Projections.projectionList()
.add(Projections.property("ID"), "id")
.add(Projections.property("favoriteName"), "favoriteName")
.add(Projections.property("properties"), "properties"))
.setResultTransformer(Transformers.aliasToBean(FavoriteImpl.class))
.setFetchMode("properties", FetchMode.JOIN);
return crit.list();
I always get an ArrayIndexOutOfBounds Exception, but I don't know why:
Code:
java.lang.ArrayIndexOutOfBoundsException: 2
at org.hibernate.loader.criteria.CriteriaLoader.getResultColumnOrRow(CriteriaLoader.java:148)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:639)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
What could be the problem? Can you give me a hint?
(I use hibernate-core 3.6.0 Final)
Regards, jacquipre.