12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 4 ■ MANAGING PERSISTENT OBJECTSQuery setParameter(String name, Calendar value, TemporalType temporalType);Query setParameter(int position, Object value);Query setParameter(int position, Date value, TemporalType temporalType);Query setParameter(int position, Calendar value, TemporalType temporalType); Query setParameter(Parameter param, T value);Query setParameter(Parameter param, Date value, TemporalType temporalType);Query setParameter(Parameter param, Calendar value, TemporalType temporalType);// Gets parameters from the querySet getParameter(String name);Parameter getParameter(int position); Parameter getParameter(String name, Class type); Parameter getParameter(int position, Class type);boolean isBound(Parameter param); T getParameterValue(Parameter param);Object getParameterValue(String name);Object getParameterValue(int position);// Constrains the number of results returned by a queryQuery setMaxResults(int maxResult);int getMaxResults();Query setFirstResult(int startPosition);int getFirstResult();// Sets and gets query hintsQuery setHint(String hintName, Object value);Map getHints();// Sets the flush mode type to be used for the query executionQuery setFlushMode(FlushModeType flushMode);FlushModeType getFlushMode();// Sets the lock mode type to be used for the query executionQuery setLockMode(LockModeType lockMode);LockModeType getLockMode();}// Allows access to the provider-specific API T unwrap(Class cls);The methods that are mostly used in this API are ones that execute the query itself. To execute aSELECT query, you have to choose between two methods depending on the required result:• The method getResultList() executes the query and returns a list of results(entities, attributes, expressions, etc.).• The getSingleResult() method executes the query and returns a single result.153

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!