Mykola M 13年 前 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; 投票するためにはログインが必要です。 次として送信する: キャンセル
Umer Sayeed 11年 前 How to use dynamic query for (NOT EQUAL TO) in liferay..,Eg..,SELECT * FROM table where userid!='10'; 投票するためにはログインが必要です。 次として送信する: キャンセル Mykola M Umer Sayeed 11年 前 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. 投票するためにはログインが必要です。 次として送信する: キャンセル Mykola M Mykola M 11年 前 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). 投票するためにはログインが必要です。 次として送信する: キャンセル le xi zhang Umer Sayeed 10年 前 ne!!!!or not ??? 投票するためにはログインが必要です。 次として送信する: キャンセル
Mykola M Umer Sayeed 11年 前 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. 投票するためにはログインが必要です。 次として送信する: キャンセル Mykola M Mykola M 11年 前 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). 投票するためにはログインが必要です。 次として送信する: キャンセル
Mykola M Mykola M 11年 前 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). 投票するためにはログインが必要です。 次として送信する: キャンセル