HHH-6520 if no @GeneratedValue on an simple @Id property, then the generator type should be assigned
This commit is contained in:
parent
5a00cb9276
commit
3689e533fb
|
@ -27,6 +27,8 @@ import java.io.Serializable;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
||||
/**
|
||||
* Identifier generator container, Useful to keep named generator in annotations
|
||||
*
|
||||
|
@ -42,7 +44,12 @@ public class IdGenerator implements Serializable {
|
|||
Map<String, String> parameters ) {
|
||||
this.name = name;
|
||||
this.strategy = strategy;
|
||||
this.parameters = parameters;
|
||||
if ( CollectionHelper.isEmpty( parameters ) ) {
|
||||
this.parameters = Collections.emptyMap();
|
||||
}
|
||||
else {
|
||||
this.parameters = Collections.unmodifiableMap( parameters );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,13 +70,6 @@ public class IdGenerator implements Serializable {
|
|||
* @return generator configuration parameters
|
||||
*/
|
||||
public Map<String, String> getParameters() {
|
||||
Map<String, String> returnedParameters;
|
||||
if ( parameters == null ) {
|
||||
returnedParameters = Collections.emptyMap();
|
||||
}
|
||||
else {
|
||||
returnedParameters = Collections.unmodifiableMap(parameters);
|
||||
}
|
||||
return returnedParameters;
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ import java.lang.reflect.Member;
|
|||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.beans.BeanInfoHelper;
|
||||
import org.hibernate.metamodel.binding.AbstractCollectionElement;
|
||||
|
@ -48,6 +50,7 @@ import org.hibernate.metamodel.binding.ComponentAttributeBinding;
|
|||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.EntityDiscriminator;
|
||||
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
|
||||
import org.hibernate.metamodel.binding.IdGenerator;
|
||||
import org.hibernate.metamodel.binding.InheritanceType;
|
||||
import org.hibernate.metamodel.binding.ManyToOneAttributeBinding;
|
||||
import org.hibernate.metamodel.binding.MetaAttribute;
|
||||
|
@ -328,9 +331,15 @@ public class Binder {
|
|||
);
|
||||
|
||||
entityBinding.getHierarchyDetails().getEntityIdentifier().setValueBinding( idAttributeBinding );
|
||||
IdGenerator generator = identifierSource.getIdentifierGeneratorDescriptor();
|
||||
if(generator == null){
|
||||
Map<String,String> params = new HashMap<String, String>( );
|
||||
params.put( IdentifierGenerator.ENTITY_NAME, entityBinding.getEntity().getName() );
|
||||
generator = new IdGenerator( "default_assign_identity_generator", "assigned", params );
|
||||
}
|
||||
entityBinding.getHierarchyDetails()
|
||||
.getEntityIdentifier()
|
||||
.setIdGenerator( identifierSource.getIdentifierGeneratorDescriptor() );
|
||||
.setIdGenerator( generator );
|
||||
|
||||
final org.hibernate.metamodel.relational.Value relationalValue = idAttributeBinding.getValue();
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import javax.persistence.Id;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.id.Assigned;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.IdentityGenerator;
|
||||
import org.hibernate.id.MultipleHiLoPerTableGenerator;
|
||||
|
@ -39,10 +40,14 @@ import org.hibernate.id.SequenceHiLoGenerator;
|
|||
import org.hibernate.id.UUIDHexGenerator;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.binding.EntityIdentifier;
|
||||
import org.hibernate.metamodel.source.MappingException;
|
||||
import org.hibernate.metamodel.source.internal.IdentifierGeneratorResolver;
|
||||
import org.hibernate.service.ServiceRegistryBuilder;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
@ -61,8 +66,12 @@ public class IdentifierGeneratorTest extends BaseAnnotationBindingTestCase {
|
|||
@Resources(annotatedClasses = NoGenerationEntity.class)
|
||||
public void testNoIdGeneration() {
|
||||
EntityBinding binding = getEntityBinding( NoGenerationEntity.class );
|
||||
IdentifierGenerator generator = binding.getHierarchyDetails().getEntityIdentifier().getIdentifierGenerator();
|
||||
assertNull( generator );
|
||||
EntityIdentifier identifier = binding.getHierarchyDetails().getEntityIdentifier();
|
||||
IdentifierGenerator generator =identifier.getIdentifierGenerator();
|
||||
assertNotNull( generator );
|
||||
assertEquals( "Wrong generator", Assigned.class, generator.getClass() );
|
||||
assertFalse( identifier.isEmbedded() );
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
|
|
@ -38,9 +38,9 @@ public abstract class AbstractOperationTestCase extends BaseCoreFunctionalTestCa
|
|||
cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "0" );
|
||||
}
|
||||
|
||||
// public String[] getMappings() {
|
||||
// return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml", "ops/Competition.hbm.xml" };
|
||||
// }
|
||||
public String[] getMappings() {
|
||||
return new String[] { "ops/Node.hbm.xml", "ops/Employer.hbm.xml", "ops/OptLockEntity.hbm.xml", "ops/OneToOne.hbm.xml", "ops/Competition.hbm.xml" };
|
||||
}
|
||||
|
||||
public String getCacheConcurrencyStrategy() {
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue