HHH-9083 throw AnnotationException for out of place @Immutable

This commit is contained in:
Brett Meyer 2014-03-25 14:33:04 -04:00
parent 519acb2749
commit c1a5622a7e
2 changed files with 19 additions and 19 deletions

View File

@ -25,15 +25,16 @@ package org.hibernate.metamodel.source.internal.annotations.attribute;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import org.hibernate.AnnotationException;
import org.hibernate.metamodel.reflite.spi.MemberDescriptor; import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
import org.hibernate.metamodel.source.internal.AttributeConversionInfo; import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata;
import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper; import org.hibernate.metamodel.source.internal.annotations.util.ConverterAndOverridesHelper;
import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.spi.AttributePath; import org.hibernate.metamodel.source.spi.AttributePath;
import org.hibernate.metamodel.source.spi.AttributeRole; import org.hibernate.metamodel.source.spi.AttributeRole;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
/** /**
@ -55,6 +56,11 @@ public abstract class AbstractSingularAttribute
String accessorStrategy) { String accessorStrategy) {
super( container, attributeName, attributePath, attributeRole, backingMember, nature, accessType, accessorStrategy ); super( container, attributeName, attributePath, attributeRole, backingMember, nature, accessType, accessorStrategy );
if ( backingMember.getAnnotations().containsKey( HibernateDotNames.IMMUTABLE ) ) {
throw new AnnotationException( "@Immutable can be used on entities or collections, not "
+ attributeRole.getFullPath() );
}
ConverterAndOverridesHelper.INSTANCE.processConverters( ConverterAndOverridesHelper.INSTANCE.processConverters(
getPath(), getPath(),
getNature(), getNature(),

View File

@ -23,26 +23,22 @@
*/ */
package org.hibernate.test.annotations.immutable; package org.hibernate.test.annotations.immutable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jboss.logging.Logger;
import org.junit.Test;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.metamodel.MetadataSources;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.jboss.logging.Logger;
import static org.junit.Assert.assertEquals; import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* Tests for <code>Immutable</code> annotation. * Tests for <code>Immutable</code> annotation.
@ -154,13 +150,11 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@FailureExpectedWithNewMetamodel
public void testMisplacedImmutableAnnotation() { public void testMisplacedImmutableAnnotation() {
// todo : metamodel is not applying many "out of place" validations
try { try {
Configuration config = new Configuration(); MetadataSources sources = new MetadataSources( serviceRegistry().getParentServiceRegistry() );
config.addAnnotatedClass(Foobar.class); sources.addAnnotatedClass(Foobar.class);
config.buildMappings( ); sources.buildMetadata();
fail(); fail();
} }
catch (AnnotationException ae) { catch (AnnotationException ae) {
@ -170,6 +164,6 @@ public class ImmutableTest extends BaseCoreFunctionalTestCase {
@Override @Override
protected Class[] getAnnotatedClasses() { protected Class[] getAnnotatedClasses() {
return new Class[] { Country.class, State.class}; return new Class[] { Country.class, State.class };
} }
} }