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 org.hibernate.AnnotationException;
import org.hibernate.metamodel.reflite.spi.MemberDescriptor;
import org.hibernate.metamodel.source.internal.AttributeConversionInfo;
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.HibernateDotNames;
import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames;
import org.hibernate.metamodel.source.spi.AttributePath;
import org.hibernate.metamodel.source.spi.AttributeRole;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.jboss.logging.Logger;
/**
@ -55,6 +56,11 @@ public abstract class AbstractSingularAttribute
String 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(
getPath(),
getNature(),

View File

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