From 9b9d7998011c0051a3349596bd9da55f1e36227b Mon Sep 17 00:00:00 2001 From: Sharath Reddy Date: Sun, 9 May 2010 18:28:33 +0000 Subject: [PATCH] HHH-4647 Problems with @JoinColumn referencedColumnName and quoted column and table names git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19433 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../annotations/backquotes/BackquoteTest.java | 29 ++++++++++ .../test/annotations/backquotes/Printer.java | 48 +++++++++++++++ .../annotations/backquotes/PrinterCable.java | 58 +++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 annotations/src/test/java/org/hibernate/test/annotations/backquotes/Printer.java create mode 100644 annotations/src/test/java/org/hibernate/test/annotations/backquotes/PrinterCable.java diff --git a/annotations/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java b/annotations/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java index f8ab5ee533..9fd2fae88a 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/backquotes/BackquoteTest.java @@ -6,6 +6,7 @@ import java.io.StringWriter; import junit.framework.TestCase; +import org.hibernate.MappingException; import org.hibernate.cfg.AnnotationConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,4 +35,32 @@ public class BackquoteTest extends TestCase { fail(e.getMessage()); } } + + /** + * HHH-4647 : Problems with @JoinColumn referencedColumnName and quoted column and table names + * + * An invalid referencedColumnName to an entity having a quoted table name results in an + * infinite loop in o.h.c.Configuration$MappingsImpl#getPhysicalColumnName(). + * The same issue exists with getLogicalColumnName() + */ + public void testInvalidReferenceToQuotedTableName() { + try { + AnnotationConfiguration config = new AnnotationConfiguration(); + config.addAnnotatedClass(Printer.class); + config.addAnnotatedClass(PrinterCable.class); + config.buildSessionFactory(); + fail("expected MappingException to be thrown"); + } + //we WANT MappingException to be thrown + catch( MappingException e ) { + assertTrue("MappingException was thrown", true); + } + catch(Exception e) { + StringWriter writer = new StringWriter(); + e.printStackTrace(new PrintWriter(writer)); + log.debug(writer.toString()); + fail(e.getMessage()); + } + } + } diff --git a/annotations/src/test/java/org/hibernate/test/annotations/backquotes/Printer.java b/annotations/src/test/java/org/hibernate/test/annotations/backquotes/Printer.java new file mode 100644 index 0000000000..6b2b69f50a --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/backquotes/Printer.java @@ -0,0 +1,48 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third- + * party contributors as indicated by the @author tags or express + * copyright attribution statements applied by the authors. + * All third-party contributions are distributed under license by + * Red Hat, Inc. + * + * This copyrighted material is made available to anyone wishing to + * use, modify, copy, or redistribute it subject to the terms and + * conditions of the GNU Lesser General Public License, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this distribution; if not, write to: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + +package org.hibernate.test.annotations.backquotes; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + + +@Entity +@Table(name="`Printer`") +public class Printer { + private Long id; + + @Id + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} \ No newline at end of file diff --git a/annotations/src/test/java/org/hibernate/test/annotations/backquotes/PrinterCable.java b/annotations/src/test/java/org/hibernate/test/annotations/backquotes/PrinterCable.java new file mode 100644 index 0000000000..cf4186bd45 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/backquotes/PrinterCable.java @@ -0,0 +1,58 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third- + * party contributors as indicated by the @author tags or express + * copyright attribution statements applied by the authors. + * All third-party contributions are distributed under license by + * Red Hat, Inc. + * + * This copyrighted material is made available to anyone wishing to + * use, modify, copy, or redistribute it subject to the terms and + * conditions of the GNU Lesser General Public License, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this distribution; if not, write to: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + +package org.hibernate.test.annotations.backquotes; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +@Entity +public class PrinterCable { + private Long id; + private Printer printer; + + @Id + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + @ManyToOne + @JoinColumn(name="aId", referencedColumnName="missing") + public Printer getPrinter() { + return printer; + } + + public void setPrinter(Printer a) { + this.printer = a; + } +} \ No newline at end of file