Skip to content

Instantly share code, notes, and snippets.

@gbadner
gbadner / gist:943347
Created April 26, 2011 22:37
Process for building SessionFactory
Build ServiceRegistry
---------------------
Map config = ...;
A) ServiceRegistry serviceRegistry =
new ServiceRegistryBuilder( config )
...
.buildServiceRegistry();
MetadataImpl constructor:
public MetadataImpl(MetadataSources metadataSources, ProcessingOrder preferredProcessingOrder) {
this.serviceRegistry = metadataSources.getServiceRegistry();
this.namingStrategy = metadataSources.getNamingStrategy();
final ArrayList<String> processedEntityNames = new ArrayList<String>();
if ( preferredProcessingOrder == ProcessingOrder.HBM_FIRST ) {
applyHibernateMappings( metadataSources, processedEntityNames );
applyAnnotationMappings( metadataSources, processedEntityNames );
@gbadner
gbadner / gist:948758
Created April 29, 2011 18:22
Metamodel tasks
1) MetadataSources -> Metadata -> SessionFactory process
[HHH-6107] - Metamodel dependence on ServiceRegistry (Steve: done)
[HHH-6138] - Implement addition of annotated classes and packages in MetadataSources (Steve: done)
[HHH-6141] - Develop scheme for ordered processing of MetadataSources sources (Steve: done)
A) for HBM XML
[HHH-2578] - redesign SessionFactory building (Steve: done)
[HHH-6145] - Create an "xml binding" service (Steve: open)
B) for EM
[HHH-6149] - Clean up EJB3Configuration (Steve: open)
[HHH-6159] - Determine best way to handle EntityManagerFactory building
@gbadner
gbadner / gist:974835
Created May 16, 2011 16:56
Entity/Attribute Binding
HHH-6227 will provide a way to update Entity/Attribute objects in EntityBinding/AttributeBinding objects
EntityBinding entityBinding =
new EntityBinding( name )
.initialize( new HbmEntityBindingState( getHibernateMappingBinder(), ... )
.initialize( new HbmEntityRelationalState( getHibernateMappingBinder(), ... );
entityBinding.setEntity( new Entity( name ) ) can be called immediately or later
@gbadner
gbadner / gist:981804
Created May 19, 2011 21:34
Clarification of Attribute/Value Bindings
In the new metamodel code, it appears that both "Attribute" and "Value" bindings are modelled using AttributeBinding. The places I've seen references to "Value" bindings (EntityIdentifier, Discriminator) don't necessarily have a domain representation.
I'm working on @IdClass, and this an example where the IdClass itself does not have a representation in the domain model.
I'd like to make some improvements.
NOTE: This uses POJO terminology; this applies to other entity modes as well.
EntityBinding knows about 3 different kinds of bindings:
@gbadner
gbadner / gist:1023040
Created June 13, 2011 15:52
How to resolve type in metamodel?
How should persisters get property type (i.e. o.h.type.Type)?
Alternatives:
1) in MetamodelImpl: new MetamodelTypeResolver( this ).resolve();
2) in persisters: attributeBinding.getType( typeResolver );
- typeResolver would be the TypeResolver scoped to the SessionFactory
@gbadner
gbadner / gist:1023221
Created June 13, 2011 17:18
How should entity modes be dealt with in new metamodel?
IIRC, an entity can only exist in one entity mode per SessionFactory.
If this is correct, then o.h.metamodel.domain.Entity does not need:
private final PojoEntitySpecifics pojoEntitySpecifics = new PojoEntitySpecifics();
private final Dom4jEntitySpecifics dom4jEntitySpecifics = new Dom4jEntitySpecifics();
private final MapEntitySpecifics mapEntitySpecifics = new MapEntitySpecifics();
It only needs:
@gbadner
gbadner / gist:1035866
Created June 20, 2011 15:54
ClassHolder
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@gbadner
gbadner / gist:1035874
Created June 20, 2011 15:57
MetadataImpl ClassHolder usage
@Override
public ClassHolder getOrCreateClassHolder(String className) {
ClassHolder classHolder = classHoldersByName.get( className );
if ( classHolder == null ) {
classHolder = ClassHolderImpl.createDeferredClassHolder( className, classLoaderService() );
classHoldersByName.put( className, classHolder );
}
return classHolder;
}
@gbadner
gbadner / gist:1035881
Created June 20, 2011 16:00
ClassHolderImpl
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU