mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 00:24:57 +00:00
HHH-12046 - Don't consider static methods for isFoo()/getFoo() conflicts.
This commit is contained in:
parent
ce21f133d2
commit
88b1e33d72
@ -457,6 +457,10 @@ private static Method getGetterOrNull(Class containerClass, String propertyName)
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( Modifier.isStatic( method.getModifiers() ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String methodName = method.getName();
|
||||
|
||||
// try "get"
|
||||
@ -492,7 +496,7 @@ private static void verifyNoIsVariantExists(
|
||||
// verify that the Class does not also define a method with the same stem name with 'is'
|
||||
try {
|
||||
final Method isMethod = containerClass.getDeclaredMethod( "is" + stemName );
|
||||
if ( isMethod.getAnnotation( Transient.class ) == null ) {
|
||||
if ( !Modifier.isStatic( isMethod.getModifiers() ) && isMethod.getAnnotation( Transient.class ) == null ) {
|
||||
// No such method should throw the caught exception. So if we get here, there was
|
||||
// such a method.
|
||||
checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod );
|
||||
@ -534,7 +538,7 @@ private static void verifyNoGetVariantExists(
|
||||
final Method getMethod = containerClass.getDeclaredMethod( "get" + stemName );
|
||||
// No such method should throw the caught exception. So if we get here, there was
|
||||
// such a method.
|
||||
if ( getMethod.getAnnotation( Transient.class ) == null ) {
|
||||
if ( !Modifier.isStatic( getMethod.getModifiers() ) && getMethod.getAnnotation( Transient.class ) == null ) {
|
||||
checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod );
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.AfterClass;
|
||||
@ -26,6 +27,7 @@
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
@ -97,6 +99,18 @@ public void testAnnotationsFieldAccess() {
|
||||
assertNotNull( metadata.getEntityBinding( AnotherEntity.class.getName() ).getIdentifierProperty() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12046" )
|
||||
public void testInstanceStaticConflict() {
|
||||
Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( InstanceStaticEntity.class )
|
||||
.buildMetadata();
|
||||
assertNotNull( metadata.getEntityBinding( InstanceStaticEntity.class.getName() ).getIdentifier() );
|
||||
assertNotNull( metadata.getEntityBinding( InstanceStaticEntity.class.getName() ).getIdentifierProperty() );
|
||||
assertTrue( metadata.getEntityBinding( InstanceStaticEntity.class.getName() ).hasProperty("foo") );
|
||||
ReflectHelper.findGetterMethod( InstanceStaticEntity.class, "foo" );
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class TheEntity {
|
||||
private Integer id;
|
||||
@ -153,4 +167,34 @@ public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class InstanceStaticEntity {
|
||||
|
||||
private Integer id;
|
||||
private boolean foo;
|
||||
|
||||
@Id
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isFoo() {
|
||||
return this.foo;
|
||||
}
|
||||
public void setFoo(boolean foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
public static Object getFoo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isId() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user