I am trying to get hibernate to return to an object that has the lowest ID number that is a fixed value More than.
Code
Criteria = session createCriteria (Story.class); Criterion storyId = Restrictions .ge ("id", 2); Projection list projections = Projection Projection list (); ProjList.add (Projections.min ("id")); Criteria.add (storyId); Criteria.setProjection (projList); List & lt ;? & Gt; StoryResult = criteria.list (); Session.close (); Story Story = (story) storyResult.get (0);
Now it is returning "3" as an integer 3 is the next available ID, but why do I have to hibernate to give an integer rather than an object? By adding
thanks
SELECT MIN (ID) to the table in
. Query This is one of the features of launch. What you really want to achieve, you have to use the projection to get the ID and use another query to retrieve the object.
Ex> Criteria idQuery = Session Creation classification (story class); IdQuery.add (restrictions .ge ("id", 2)); IdQuery.setProjection (Projections.min ("id")); Int return ID = Criteria. Sequential results (); Criterion storyQuery = session. Creation classification (story class); StoryQuery.add (restrictionsIiAk (Returned ID); Story Story = (story) storyQuery.uniqueResult (); Return Story;
No comments:
Post a Comment