Hi,
First, thank you for your reply, but I really don't understand what you are asking me :-)
I have a collection of Long, the Object Long, the wrapper around the basic datatype long. So, i want to query the value of the Long ;-)
I have tried several ways, but it does not work:
When I want to create an alias like this :
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(DBUser.class);
criteria.createAlias("myElements", "collection")
criteria.add(Property.forName("collection").eq(1L));
OR
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(DBUser.class);
criteria.createAlias("myElements", "e")
criteria.add(Property.forName("e.element").eq(1L));
I get following exception:
Code:
[junit] Caused by: org.hibernate.MappingException: collection was not an association: com.freiheit.ark.user.model.persistence.DBUser.myElements
[junit] at org.hibernate.type.CollectionType.getAssociatedEntityName(CollectionType.java:385)
[junit] at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:207)
[junit] at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:191)
[junit] at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:81)
[junit] at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:59)
[junit] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
[junit] at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
But it is a collection and so why is it not an association?
OK, so I tried the diffrent way, don't create an alias (I know, the alias should make the join to the collection):
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(DBUser.class);
criteria.add(Property.forName("myElements").eq(1L));
Of course, this will produce an error:
Code:
[junit] Caused by: org.postgresql.util.PSQLException: Für den Parameter 1 wurde kein Wert angegeben.
[junit] at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:134)
[junit] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:179)
[junit] at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:437)
[junit] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:353)
[junit] at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:257)
[junit] at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
[junit] at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
[junit] at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
[junit] at org.hibernate.loader.Loader.doQuery(Loader.java:662)
[junit] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
[junit] at org.hibernate.loader.Loader.doList(Loader.java:2144)
[junit] ... 37 more
SO, once again, is it possible to query special elements in a collectionOfElements? And if yes,... how?