HHH-10456: Report the class name were the invalid PrimaryKeyJoinColumn is present
This commit is contained in:
parent
849c4d21f6
commit
de6d80a67b
|
@ -1242,7 +1242,7 @@ public final class AnnotationBinder {
|
||||||
else {
|
else {
|
||||||
if ( clazzToProcess.isAnnotationPresent( PrimaryKeyJoinColumns.class )
|
if ( clazzToProcess.isAnnotationPresent( PrimaryKeyJoinColumns.class )
|
||||||
|| clazzToProcess.isAnnotationPresent( PrimaryKeyJoinColumn.class ) ) {
|
|| clazzToProcess.isAnnotationPresent( PrimaryKeyJoinColumn.class ) ) {
|
||||||
LOG.invalidPrimaryKeyJoinColumnAnnotation();
|
LOG.invalidPrimaryKeyJoinColumnAnnotation( clazzToProcess.getName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return inheritanceJoinedColumns;
|
return inheritanceJoinedColumns;
|
||||||
|
|
|
@ -445,8 +445,8 @@ public interface CoreMessageLogger extends BasicLogger {
|
||||||
void invalidOnDeleteAnnotation(String entityName);
|
void invalidOnDeleteAnnotation(String entityName);
|
||||||
|
|
||||||
@LogMessage(level = WARN)
|
@LogMessage(level = WARN)
|
||||||
@Message(value = "Root entity should not hold an PrimaryKeyJoinColum(s), will be ignored", id = 137)
|
@Message(value = "Root entity should not hold an PrimaryKeyJoinColum(s), will be ignored: %s", id = 137)
|
||||||
void invalidPrimaryKeyJoinColumnAnnotation();
|
void invalidPrimaryKeyJoinColumnAnnotation(String className);
|
||||||
|
|
||||||
@LogMessage(level = WARN)
|
@LogMessage(level = WARN)
|
||||||
@Message(value = "Mixing inheritance strategy in a entity hierarchy is not allowed, ignoring sub strategy in: %s",
|
@Message(value = "Mixing inheritance strategy in a entity hierarchy is not allowed, ignoring sub strategy in: %s",
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* 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.test.cfg;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.PrimaryKeyJoinColumn;
|
||||||
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.cfg.AnnotationBinder;
|
||||||
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||||
|
import org.hibernate.testing.logger.Triggerable;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dominique Toupin
|
||||||
|
*/
|
||||||
|
@TestForIssue(jiraKey = "HHH-10456")
|
||||||
|
public class AnnotationBinderTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||||
|
Logger.getMessageLogger( CoreMessageLogger.class, AnnotationBinder.class.getName() ) );
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidPrimaryKeyJoinColumnAnnotationMessageContainsClassName() throws Exception {
|
||||||
|
|
||||||
|
Triggerable triggerable = logInspection.watchForLogMessages( "HHH000137" );
|
||||||
|
|
||||||
|
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder();
|
||||||
|
|
||||||
|
Metadata metadata = new MetadataSources( srb.build() )
|
||||||
|
.addAnnotatedClass( InvalidPrimaryKeyJoinColumnAnnotationEntity.class )
|
||||||
|
.buildMetadata();
|
||||||
|
|
||||||
|
assertTrue( "Expected warning HHH00137 but it wasn't triggered", triggerable.wasTriggered() );
|
||||||
|
assertTrue( "Expected invalid class name in warning HHH00137 message but it does not apper to be present; got " + triggerable.triggerMessage(),
|
||||||
|
triggerable.triggerMessage().matches( ".*\\b\\Q" + InvalidPrimaryKeyJoinColumnAnnotationEntity.class.getName() + "\\E\\b.*" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@PrimaryKeyJoinColumn
|
||||||
|
public static class InvalidPrimaryKeyJoinColumnAnnotationEntity {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.testing.logger;
|
package org.hibernate.testing.logger;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import org.jboss.logging.Logger.Level;
|
import org.jboss.logging.Logger.Level;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ final class TriggerOnPrefixLogListener implements LogListener, Triggerable {
|
||||||
|
|
||||||
private final String expectedPrefix;
|
private final String expectedPrefix;
|
||||||
private final AtomicBoolean triggered = new AtomicBoolean( false );
|
private final AtomicBoolean triggered = new AtomicBoolean( false );
|
||||||
|
private final AtomicReference<String> triggerMessage = new AtomicReference<String>( null );
|
||||||
|
|
||||||
public TriggerOnPrefixLogListener(String expectedPrefix) {
|
public TriggerOnPrefixLogListener(String expectedPrefix) {
|
||||||
this.expectedPrefix = expectedPrefix;
|
this.expectedPrefix = expectedPrefix;
|
||||||
|
@ -23,9 +25,15 @@ final class TriggerOnPrefixLogListener implements LogListener, Triggerable {
|
||||||
public void loggedEvent(Level level, String renderedMessage, Throwable thrown) {
|
public void loggedEvent(Level level, String renderedMessage, Throwable thrown) {
|
||||||
if ( renderedMessage != null && renderedMessage.startsWith( expectedPrefix ) ) {
|
if ( renderedMessage != null && renderedMessage.startsWith( expectedPrefix ) ) {
|
||||||
triggered.set( true );
|
triggered.set( true );
|
||||||
|
triggerMessage.set(renderedMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String triggerMessage() {
|
||||||
|
return triggerMessage.get();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean wasTriggered() {
|
public boolean wasTriggered() {
|
||||||
return triggered.get();
|
return triggered.get();
|
||||||
|
@ -34,6 +42,6 @@ final class TriggerOnPrefixLogListener implements LogListener, Triggerable {
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
triggered.set( false );
|
triggered.set( false );
|
||||||
|
triggerMessage.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,9 @@ package org.hibernate.testing.logger;
|
||||||
|
|
||||||
public interface Triggerable {
|
public interface Triggerable {
|
||||||
|
|
||||||
|
String triggerMessage();
|
||||||
|
|
||||||
boolean wasTriggered();
|
boolean wasTriggered();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue