javax.persistence.PersistenceUnitUtil Java Examples
The following examples show how to use
javax.persistence.PersistenceUnitUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ViewPostBean.java From ee7-sandbox with Apache License 2.0 | 6 votes |
public void init() { log.info("call init, id @" + id); if (id != null) { //this.post = em.find(Post.class, this.id); EntityGraph postEntityGraph=em.getEntityGraph("post"); // EntityGraph postEntityGraph=em.createEntityGraph(Post.class); // postEntityGraph.addAttributeNodes("title"); // postEntityGraph.addSubgraph("comments").addAttributeNodes("content"); this.post=em .createQuery("select p from Post p where p.id=:id", Post.class) .setHint("javax.persistence.loadgraph", postEntityGraph) .setParameter("id", this.id) .getResultList() .get(0); PersistenceUnitUtil util=em.getEntityManagerFactory().getPersistenceUnitUtil(); log.info("title is loadded@"+util.isLoaded(this.post, "title")); log.info("body is loadded@"+util.isLoaded(this.post, "body")); log.info("comments is loadded@"+util.isLoaded(this.post, "comments")); } else { throw new RuntimeException("id is required"); } }
Example #2
Source File: JpaUtils.java From jdal with Apache License 2.0 | 5 votes |
/** * Initialize a entity. * @param em entity manager to use * @param entity entity to initialize * @param depth max depth on recursion */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static void initialize(EntityManager em, Object entity, int depth) { // return on nulls, depth = 0 or already initialized objects if (entity == null || depth == 0) { return; } PersistenceUnitUtil unitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil(); EntityType entityType = em.getMetamodel().entity(entity.getClass()); Set<Attribute> attributes = entityType.getDeclaredAttributes(); Object id = unitUtil.getIdentifier(entity); if (id != null) { Object attached = em.find(entity.getClass(), unitUtil.getIdentifier(entity)); for (Attribute a : attributes) { if (!unitUtil.isLoaded(entity, a.getName())) { if (a.isCollection()) { intializeCollection(em, entity, attached, a, depth); } else if(a.isAssociation()) { intialize(em, entity, attached, a, depth); } } } } }
Example #3
Source File: HouseRepositoryTest.java From deltaspike with Apache License 2.0 | 5 votes |
@Test @InSequence(2) public void shouldNotLoadLazyAssociationsWithoutGraph() throws Exception { House house = repository.findOptionalByName("Bellevue"); assertNotNull(house); PersistenceUnitUtil puu = entityManager.getEntityManagerFactory().getPersistenceUnitUtil(); assertFalse(puu.isLoaded(house, "flats")); assertFalse(puu.isLoaded(house, "garages")); }
Example #4
Source File: PersistenceUnitUtilDelegateFactory.java From deltaspike with Apache License 2.0 | 5 votes |
public static PersistenceUnitUtil get(EntityManager entityManager) { final EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory(); final String vendorName = (String) entityManagerFactory.getProperties().get("VendorName"); if (vendorName != null && "openjpa".equalsIgnoreCase(vendorName)) { return new OpenJpaPersistenceUnitUtilDelegate(entityManager); } return entityManagerFactory.getPersistenceUnitUtil(); }
Example #5
Source File: LegacySessionFactory.java From judgels with GNU General Public License v2.0 | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil() { return null; }
Example #6
Source File: SessionFactoryDelegatingImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil() { return delegate.getPersistenceUnitUtil(); }
Example #7
Source File: SessionFactoryImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil() { validateNotClosed(); return jpaPersistenceUnitUtil; }
Example #8
Source File: MockStockPriceEntityManagerFactory.java From training with MIT License | 4 votes |
public PersistenceUnitUtil getPersistenceUnitUtil() { throw new UnsupportedOperationException("Not supported."); }
Example #9
Source File: CacheHibernateStoreFactorySelfTest.java From ignite with Apache License 2.0 | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil() { return null; }
Example #10
Source File: JPQLBuilderFactoryTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil() { return null; }
Example #11
Source File: TestEntityManagerFactory.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil( ) { // TODO Auto-generated method stub return null; }
Example #12
Source File: ReloadableEntityManagerFactory.java From tomee with Apache License 2.0 | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil() { return delegate().getPersistenceUnitUtil(); }
Example #13
Source File: JPQLBuilderFactoryTest.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Test public void testOdataJpaAccessFactory() { ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl(); ODataJPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl .getODataJPAAccessFactory(); ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl(); EntityManagerFactory emf = new EntityManagerFactory() { @Override public boolean isOpen() { // TODO Auto-generated method stub return false; } @Override public Map<String, Object> getProperties() { // TODO Auto-generated method stub return null; } @Override public PersistenceUnitUtil getPersistenceUnitUtil() { // TODO Auto-generated method stub return null; } @Override public Metamodel getMetamodel() { // TODO Auto-generated method stub return null; } @Override public CriteriaBuilder getCriteriaBuilder() { // TODO Auto-generated method stub return null; } @Override public Cache getCache() { // TODO Auto-generated method stub return null; } @SuppressWarnings("rawtypes") @Override public EntityManager createEntityManager(final Map arg0) { // TODO Auto-generated method stub return null; } @Override public EntityManager createEntityManager() { // TODO Auto-generated method stub return null; } @Override public void close() { // TODO Auto-generated method stub } }; oDataJPAContextImpl.setEntityManagerFactory(emf); oDataJPAContextImpl.setPersistenceUnitName("pUnit"); assertNotNull(jpaAccessFactory.getODataJPAMessageService(new Locale( "en"))); assertNotNull(jpaAccessFactory.createODataJPAContext()); assertNotNull(jpaAccessFactory .createJPAEdmProvider(oDataJPAContextImpl)); assertNotNull(jpaAccessFactory .createODataProcessor(oDataJPAContextImpl)); }
Example #14
Source File: EntityRepositoryHandler.java From deltaspike with Apache License 2.0 | 4 votes |
private PersistenceUnitUtil persistenceUnitUtil() { return PersistenceUnitUtilDelegateFactory.get(entityManager()); }
Example #15
Source File: TestPersistenceProviderResolver.java From deltaspike with Apache License 2.0 | 4 votes |
@Override public PersistenceUnitUtil getPersistenceUnitUtil() { return null; }