HHH-9083 throw AnnotationException for out of place @Immutable
This commit is contained in:
parent
519acb2749
commit
c1a5622a7e
|
@ -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(),
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue