Mykola M Vor 13 Jahren Great article, thanks a lot for sharing this knowledge.One insignificant remark:> A fourth gotcha is that even if you don't specify a projection> (thus resulting in a default of selecting all columns and implied "give me the entity"),> casting directly to a List<T> won't work as it does in custom finders, > because you're getting back a List<Object>, not a List.> The quick and dirty solution is to either (a) use addAll on a List > and typecast (simulating what happens in a custom finder), > or (b) add each result to a List<T> (cleaner to read).Adding each result one by one is unnecessary overhead, as is creation as another List implementation instance (a quite small overhead, but still unnecessary).This can be easily avoided by using code like this:List<T> listOfT = (List<T>) (List) listOfObject; Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen
Umer Sayeed Vor 11 Jahren How to use dynamic query for (NOT EQUAL TO) in liferay..,Eg..,SELECT * FROM table where userid!='10'; Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen Mykola M Umer Sayeed Vor 11 Jahren Hi Umer SayeedIt's similar to equals condition described in article. See there is:Criterion criterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Here RestrictionsFactoryUtil creates "equal" condition on eq method call.Same way RestrictionsFactoryUtil method ne can be used:Criterion criterion = RestrictionsFactoryUtil.ne("primaryKey.userId", userId);This will create "not equals" condition.Regards,Mykola Makhin. Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen Mykola M Mykola M Vor 11 Jahren P.S. Note also that you can negate any condition using RestrictionFactoryUtil.not(Criterion criterion) method.I.e. same thing could be done this way (same result, just 2 lines of code instead of 1):Criterion eqCriterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Criterion notEqCriterion = RestrictionFactoryUtil.not(eqCriterion);P.P.S. I also recommend you to look up RestrictionsFactoryImpl class source code when you have questions like this - you'll see what the methods actually do, as this factory is essentially proxying calls to Hibernate's org.hibernate.criterion.Restrictions util (documentation on which you can fine on Hibernate site - in case you're not familiar with it already), and wraps hibernate Criterion into Liferay's wrapper Criterion (see CriterionImpl). Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen le xi zhang Umer Sayeed Vor 10 Jahren ne!!!!or not ??? Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen
Mykola M Umer Sayeed Vor 11 Jahren Hi Umer SayeedIt's similar to equals condition described in article. See there is:Criterion criterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Here RestrictionsFactoryUtil creates "equal" condition on eq method call.Same way RestrictionsFactoryUtil method ne can be used:Criterion criterion = RestrictionsFactoryUtil.ne("primaryKey.userId", userId);This will create "not equals" condition.Regards,Mykola Makhin. Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen Mykola M Mykola M Vor 11 Jahren P.S. Note also that you can negate any condition using RestrictionFactoryUtil.not(Criterion criterion) method.I.e. same thing could be done this way (same result, just 2 lines of code instead of 1):Criterion eqCriterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Criterion notEqCriterion = RestrictionFactoryUtil.not(eqCriterion);P.P.S. I also recommend you to look up RestrictionsFactoryImpl class source code when you have questions like this - you'll see what the methods actually do, as this factory is essentially proxying calls to Hibernate's org.hibernate.criterion.Restrictions util (documentation on which you can fine on Hibernate site - in case you're not familiar with it already), and wraps hibernate Criterion into Liferay's wrapper Criterion (see CriterionImpl). Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen
Mykola M Mykola M Vor 11 Jahren P.S. Note also that you can negate any condition using RestrictionFactoryUtil.not(Criterion criterion) method.I.e. same thing could be done this way (same result, just 2 lines of code instead of 1):Criterion eqCriterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Criterion notEqCriterion = RestrictionFactoryUtil.not(eqCriterion);P.P.S. I also recommend you to look up RestrictionsFactoryImpl class source code when you have questions like this - you'll see what the methods actually do, as this factory is essentially proxying calls to Hibernate's org.hibernate.criterion.Restrictions util (documentation on which you can fine on Hibernate site - in case you're not familiar with it already), and wraps hibernate Criterion into Liferay's wrapper Criterion (see CriterionImpl). Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen
le xi zhang Umer Sayeed Vor 10 Jahren ne!!!!or not ??? Melden Sie sich an, um auf diesen Beitrag zu antworten. Antworten als... Abbrechen