Java Code Examples for org.hibernate.tuple.GenerationTiming#ALWAYS
The following examples show how to use
org.hibernate.tuple.GenerationTiming#ALWAYS .
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: PropertyBinder.java From lams with GNU General Public License v2.0 | 6 votes |
private ValueGeneration determineValueGenerationStrategy(XProperty property) { ValueGeneration valueGeneration = getValueGenerationFromAnnotations( property ); if ( valueGeneration == null ) { return NoValueGeneration.INSTANCE; } final GenerationTiming when = valueGeneration.getGenerationTiming(); if ( valueGeneration.getValueGenerator() == null ) { insertable = false; if ( when == GenerationTiming.ALWAYS ) { updatable = false; } } return valueGeneration; }
Example 2
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 4 votes |
private boolean timingsMatch(GenerationTiming timing, GenerationTiming matchTiming) { return ( matchTiming == GenerationTiming.INSERT && timing.includesInsert() ) || ( matchTiming == GenerationTiming.ALWAYS && timing.includesUpdate() ); }
Example 3
Source File: EntityMetamodel.java From lams with GNU General Public License v2.0 | 4 votes |
public GenerationStrategyPair buildPair() { if ( hadInMemoryGeneration && hadInDatabaseGeneration ) { throw new ValueGenerationStrategyException( "Composite attribute [" + mappingProperty.getName() + "] contained both in-memory" + " and in-database value generation" ); } else if ( hadInMemoryGeneration ) { throw new NotYetImplementedException( "Still need to wire in composite in-memory value generation" ); } else if ( hadInDatabaseGeneration ) { final Component composite = (Component) mappingProperty.getValue(); // we need the numbers to match up so we can properly handle 'referenced sql column values' if ( inDatabaseStrategies.size() != composite.getPropertySpan() ) { throw new ValueGenerationStrategyException( "Internal error : mismatch between number of collected in-db generation strategies" + " and number of attributes for composite attribute : " + mappingProperty.getName() ); } // the base-line values for the aggregated InDatabaseValueGenerationStrategy we will build here. GenerationTiming timing = GenerationTiming.INSERT; boolean referenceColumns = false; String[] columnValues = new String[ composite.getColumnSpan() ]; // start building the aggregate values int propertyIndex = -1; int columnIndex = 0; Iterator subProperties = composite.getPropertyIterator(); while ( subProperties.hasNext() ) { propertyIndex++; final Property subProperty = (Property) subProperties.next(); final InDatabaseValueGenerationStrategy subStrategy = inDatabaseStrategies.get( propertyIndex ); if ( subStrategy.getGenerationTiming() == GenerationTiming.ALWAYS ) { // override the base-line to the more often "ALWAYS"... timing = GenerationTiming.ALWAYS; } if ( subStrategy.referenceColumnsInSql() ) { // override base-line value referenceColumns = true; } if ( subStrategy.getReferencedColumnValues() != null ) { if ( subStrategy.getReferencedColumnValues().length != subProperty.getColumnSpan() ) { throw new ValueGenerationStrategyException( "Internal error : mismatch between number of collected 'referenced column values'" + " and number of columns for composite attribute : " + mappingProperty.getName() + '.' + subProperty.getName() ); } System.arraycopy( subStrategy.getReferencedColumnValues(), 0, columnValues, columnIndex, subProperty.getColumnSpan() ); } } // then use the aggregated values to build the InDatabaseValueGenerationStrategy return new GenerationStrategyPair( new InDatabaseValueGenerationStrategyImpl( timing, referenceColumns, columnValues ) ); } else { return NO_GEN_PAIR; } }
Example 4
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
private void bindProperty( MappingDocument mappingDocument, AttributeSource propertySource, Property property) { property.setName( propertySource.getName() ); if ( StringHelper.isNotEmpty( propertySource.getXmlNodeName() ) ) { DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfDomEntityModeSupport(); } property.setPropertyAccessorName( StringHelper.isNotEmpty( propertySource.getPropertyAccessorName() ) ? propertySource.getPropertyAccessorName() : mappingDocument.getMappingDefaults().getImplicitPropertyAccessorName() ); if ( propertySource instanceof CascadeStyleSource ) { final CascadeStyleSource cascadeStyleSource = (CascadeStyleSource) propertySource; property.setCascade( StringHelper.isNotEmpty( cascadeStyleSource.getCascadeStyleName() ) ? cascadeStyleSource.getCascadeStyleName() : mappingDocument.getMappingDefaults().getImplicitCascadeStyleName() ); } property.setOptimisticLocked( propertySource.isIncludedInOptimisticLocking() ); if ( propertySource.isSingular() ) { final SingularAttributeSource singularAttributeSource = (SingularAttributeSource) propertySource; property.setInsertable( singularAttributeSource.isInsertable() ); property.setUpdateable( singularAttributeSource.isUpdatable() ); // NOTE : Property#is refers to whether a property is lazy via bytecode enhancement (not proxies) property.setLazy( singularAttributeSource.isBytecodeLazy() ); final GenerationTiming generationTiming = singularAttributeSource.getGenerationTiming(); if ( generationTiming == GenerationTiming.ALWAYS || generationTiming == GenerationTiming.INSERT ) { // we had generation specified... // HBM only supports "database generated values" property.setValueGenerationStrategy( new GeneratedValueGeneration( generationTiming ) ); // generated properties can *never* be insertable... if ( property.isInsertable() ) { log.debugf( "Property [%s] specified %s generation, setting insertable to false : %s", propertySource.getName(), generationTiming.name(), mappingDocument.getOrigin() ); property.setInsertable( false ); } // properties generated on update can never be updatable... if ( property.isUpdateable() && generationTiming == GenerationTiming.ALWAYS ) { log.debugf( "Property [%s] specified ALWAYS generation, setting updateable to false : %s", propertySource.getName(), mappingDocument.getOrigin() ); property.setUpdateable( false ); } } } property.setMetaAttributes( propertySource.getToolingHintContext().getMetaAttributeMap() ); if ( log.isDebugEnabled() ) { final StringBuilder message = new StringBuilder() .append( "Mapped property: " ) .append( propertySource.getName() ) .append( " -> [" ); final Iterator itr = property.getValue().getColumnIterator(); while ( itr.hasNext() ) { message.append( ( (Selectable) itr.next() ).getText() ); if ( itr.hasNext() ) { message.append( ", " ); } } message.append( "]" ); log.debug( message.toString() ); } }
Example 5
Source File: ModifiedByValueGeneration.java From HibernateDemos with The Unlicense | 4 votes |
public GenerationTiming getGenerationTiming() { return GenerationTiming.ALWAYS; }
Example 6
Source File: ModifiedByValueGeneration.java From hibernate-demos with Apache License 2.0 | 4 votes |
public GenerationTiming getGenerationTiming() { return GenerationTiming.ALWAYS; }