Skip to content

Commit

Permalink
HHH-18414 Add test for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff authored and gavinking committed Aug 13, 2024
1 parent b5a5869 commit a1a4446
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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" );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class System {
@Basic
public String name;
@YesNo
@Foo
public boolean active;

private System() {
Expand Down

0 comments on commit a1a4446

Please sign in to comment.