use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class IdMetadataGenerator method addId.
@SuppressWarnings({ "unchecked" })
IdMappingData addId(PersistentClass pc, boolean audited) {
// Xml mapping which will be used for relations
final Element relIdMapping = new DefaultElement("properties");
// Xml mapping which will be used for the primary key of the versions table
final Element origIdMapping = new DefaultElement("composite-id");
final Property idProp = pc.getIdentifierProperty();
final Component idMapper = pc.getIdentifierMapper();
// Checking if the id mapping is supported
if (idMapper == null && idProp == null) {
return null;
}
SimpleIdMapperBuilder mapper;
if (idMapper != null) {
// Multiple id
final Class componentClass = ReflectionTools.loadClass(((Component) pc.getIdentifier()).getComponentClassName(), mainGenerator.getClassLoaderService());
mapper = new MultipleIdMapper(componentClass, pc.getServiceRegistry());
if (!addIdProperties(relIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), mapper, false, audited)) {
return null;
}
// null mapper - the mapping where already added the first time, now we only want to generate the xml
if (!addIdProperties(origIdMapping, (Iterator<Property>) idMapper.getPropertyIterator(), null, true, audited)) {
return null;
}
} else if (idProp.isComposite()) {
// Embedded id
final Component idComponent = (Component) idProp.getValue();
final Class embeddableClass = ReflectionTools.loadClass(idComponent.getComponentClassName(), mainGenerator.getClassLoaderService());
mapper = new EmbeddedIdMapper(getIdPropertyData(idProp), embeddableClass, pc.getServiceRegistry());
if (!addIdProperties(relIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), mapper, false, audited)) {
return null;
}
// null mapper - the mapping where already added the first time, now we only want to generate the xml
if (!addIdProperties(origIdMapping, (Iterator<Property>) idComponent.getPropertyIterator(), null, true, audited)) {
return null;
}
} else {
// Single id
mapper = new SingleIdMapper(pc.getServiceRegistry());
// Last but one parameter: ids are always insertable
mainGenerator.getBasicMetadataGenerator().addBasic(relIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), mapper, true, false);
// null mapper - the mapping where already added the first time, now we only want to generate the xml
mainGenerator.getBasicMetadataGenerator().addBasic(origIdMapping, getIdPersistentPropertyAuditingData(idProp), idProp.getValue(), null, true, true);
}
origIdMapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
// Adding a relation to the revision entity (effectively: the "revision number" property)
mainGenerator.addRevisionInfoRelation(origIdMapping);
return new IdMappingData(mapper, origIdMapping, relIdMapping);
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class BasicModelingTest method testMetamodelBuilding.
@Test
@TestForIssue(jiraKey = "HHH-9042")
public void testMetamodelBuilding() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Person.class).getMetadataBuilder().applyAttributeConverter(SexConverter.class).build();
((MetadataImpl) metadata).validate();
PersistentClass personBinding = metadata.getEntityBinding(Person.class.getName());
assertNotNull(personBinding);
PersistentClass personAuditBinding = metadata.getEntityBinding(Person.class.getName() + "_AUD");
assertNotNull(personAuditBinding);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class PutFromLoadStressTestCase method beforeClass.
@BeforeClass
public static void beforeClass() {
// Extra options located in src/test/resources/hibernate.properties
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.CACHE_REGION_FACTORY, "org.hibernate.cache.infinispan.InfinispanRegionFactory").applySetting(Environment.JTA_PLATFORM, "org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform").applySetting(Environment.USE_MINIMAL_PUTS, "false").applySetting(Environment.HBM2DDL_AUTO, "create-drop");
StandardServiceRegistry serviceRegistry = ssrb.build();
MetadataSources metadataSources = new MetadataSources(serviceRegistry).addResource("cache/infinispan/functional/Item.hbm.xml").addResource("cache/infinispan/functional/Customer.hbm.xml").addResource("cache/infinispan/functional/Contact.hbm.xml").addAnnotatedClass(Age.class);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (entityBinding instanceof RootClass) {
((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional");
}
}
for (Collection collectionBinding : metadata.getCollectionBindings()) {
collectionBinding.setCacheConcurrencyStrategy("transactional");
}
sessionFactory = metadata.buildSessionFactory();
tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class SecondLevelCacheStressTestCase method buildMetadata.
private static Metadata buildMetadata(StandardServiceRegistry registry) {
final String cacheStrategy = "transactional";
MetadataSources metadataSources = new MetadataSources(registry);
for (Class entityClass : getAnnotatedClasses()) {
metadataSources.addAnnotatedClass(entityClass);
}
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited()) {
((RootClass) entityBinding).setCacheConcurrencyStrategy(cacheStrategy);
}
}
for (Collection collectionBinding : metadata.getCollectionBindings()) {
collectionBinding.setCacheConcurrencyStrategy(cacheStrategy);
}
return metadata;
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class JBossStandaloneJtaExampleTest method buildSessionFactory.
private SessionFactory buildSessionFactory() {
// Extra options located in src/test/resources/hibernate.properties
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySetting(Environment.DIALECT, "HSQL").applySetting(Environment.HBM2DDL_AUTO, "create-drop").applySetting(Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName()).applySetting(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory").applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()).applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta").applySetting(Environment.RELEASE_CONNECTIONS, "auto").applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.JTA_PLATFORM, new JBossStandAloneJtaPlatform()).applySetting(Environment.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName());
StandardServiceRegistry serviceRegistry = ssrb.build();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
metadataSources.addResource("org/hibernate/test/cache/infinispan/functional/entities/Item.hbm.xml");
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (entityBinding instanceof RootClass) {
((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional");
}
}
for (Collection collectionBinding : metadata.getCollectionBindings()) {
collectionBinding.setCacheConcurrencyStrategy("transactional");
}
return metadata.buildSessionFactory();
}
Aggregations