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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 4 ■ MANAGING PERSISTENT OBJECTSFlushModeType getFlushMode();void lock(Object entity, LockModeType lockMode);void lock(Object entity, LockModeType lockMode, Map properties);LockModeType getLockMode(Object entity);void refresh(Object entity);void refresh(Object entity, LockModeType lockMode);void refresh(Object entity, Map properties);void refresh(Object entity, LockModeType lockMode, Map properties);void clear();void detach(Object entity);boolean contains(Object entity);Map getProperties();void setProperty(String propertyName, Object value);Query createQuery(String qlString);Query createNamedQuery(String name);Query createNativeQuery(String sqlString);Query createNativeQuery(String sqlString, Class resultClass);Query createNativeQuery(String sqlString, String resultSetMapping); TypedQuery createQuery(CriteriaQuery criteriaQuery); TypedQuery createQuery(String qlString,Class resultClass); TypedQuery createNamedQuery(String name,Class resultClass);CriteriaBuilder getCriteriaBuilder();Metamodel getMetamodel();void joinTransaction(); T unwrap(Class cls);Object getDelegate();}QueryBuilder getQueryBuilder();Don’t get scared by the API in Listing 4-4, as this chapter will cover most of the methods. In the nextsection, I explain how to get an instance of an EntityManager.Obtaining an Entity ManagerThe entity manager is the central interface to interact <strong>with</strong> entities, but it first has to be obtained by anapplication. Depending on whether it is a container-managed environment (like you’ll see in Chapter 6<strong>with</strong> EJBs) or application-managed environment, the code can be quite different. For example, in acontainer-managed environment, the transactions are managed by the container. That means you don’tneed to explicitly write the commit or rollback, which you have to do in an application-managedenvironment.128

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

Saved successfully!

Ooh no, something went wrong!