HHH-18414 Add test for issue

This commit is contained in:
Yanming Zhou 2024-08-13 09:26:20 +08:00 committed by Gavin King
parent b5a5869b9b
commit a1a4446f09
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,27 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.mapping.attributebinder;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import org.hibernate.annotations.AttributeBinderType;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Dummy annotation to verify binders are called only once.
*
* @author Yanming Zhou
*/
@Target({METHOD,FIELD})
@Retention(RUNTIME)
@AttributeBinderType( binder = FooBinder.class )
public @interface Foo {
}

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.mapping.attributebinder;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.hibernate.binder.AttributeBinder;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
/**
* The binder to verify binders are called only once.
*
* @author Yanming Zhou
*/
public class FooBinder implements AttributeBinder<Foo> {
private static final Map<String, Foo> map = new ConcurrentHashMap<>();
@Override
public void bind(
Foo annotation,
MetadataBuildingContext buildingContext,
PersistentClass persistentClass,
Property property) {
String key = persistentClass.getClassName() + "." + property.getName();
Foo existing = map.putIfAbsent( key, annotation );
if ( existing == annotation ) {
throw new IllegalStateException( "AttributeBinder is called twice" );
}
}
}

View File

@ -19,6 +19,7 @@ public class System {
@Basic
public String name;
@YesNo
@Foo
public boolean active;
private System() {