List of usage examples for org.hibernate.persister.entity EntityPersister getIdentifierGenerator
IdentifierGenerator getIdentifierGenerator();
From source file:cc.alcina.framework.entity.impl.jboss.JPAHibernateImpl.java
License:Apache License
@Override public Object beforeSpecificSetId(EntityManager entityManager, Object toPersist) throws Exception { SessionImplementor session = (SessionImplementor) entityManager.getDelegate(); EntityPersister persister = session.getEntityPersister(toPersist.getClass().getName(), toPersist); IdentifierGenerator identifierGenerator = persister.getIdentifierGenerator(); IdentifierProperty ip = persister.getEntityMetamodel().getIdentifierProperty(); IdentifierValue backupUnsavedValue = setUnsavedValue(ip, IdentifierValue.ANY, new UseEntityIdGenerator()); return new SavedId(ip, backupUnsavedValue, identifierGenerator); }
From source file:com.literatejava.hibernate.allocator.LinearBlockAllocator_FunctionalTest.java
License:Open Source License
/** test Block Allocation; * - basic functional test, //from w w w . j a va 2s .com * - use a distinct entity (EntityA) to ensure allocated IDs are as expected. */ @Test public void testBlockAllocation() { EntityPersister persister = sessionFactory().getEntityPersister(EntityA.class.getName()); assertTrue(persister.getIdentifierGenerator() instanceof LinearBlockAllocator); LinearBlockAllocator generator = (LinearBlockAllocator) persister.getIdentifierGenerator(); int count = 20; long START_FROM = 10; EntityA[] entities = new EntityA[count]; Session s = openSession(); s.beginTransaction(); for (int i = 0; i < count; i++) { String name = "entity " + (i + 1); entities[i] = new EntityA(name); s.save(entities[i]); long expectedId = START_FROM + i; assertEquals(expectedId, entities[i].getId().longValue()); } s.getTransaction().commit(); assertEquals(2, generator.getStats_TableAccessCount()); s.beginTransaction(); for (int i = 0; i < count; i++) { assertEquals(i + START_FROM, entities[i].getId().intValue()); s.delete(entities[i]); } s.getTransaction().commit(); s.close(); // pass. }