From 0cce06fb54878222d51a9f9f5c28c091a5cc1454 Mon Sep 17 00:00:00 2001 From: "s.vasilyev" Date: Tue, 3 Sep 2013 20:45:35 +0400 Subject: [PATCH] HHH-8468 test case --- .../annotations/join/namingstrategy/Life.java | 54 +++++++++++++++ .../NamingStrategyJoinTest.java | 66 +++++++++++++++++++ .../join/namingstrategy/SimpleCat.java | 58 ++++++++++++++++ .../namingstrategy/TestNamingStrategy.java | 36 ++++++++++ 4 files changed, 214 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/Life.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/NamingStrategyJoinTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/SimpleCat.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/TestNamingStrategy.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/Life.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/Life.java new file mode 100644 index 0000000000..cac3bdf456 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/Life.java @@ -0,0 +1,54 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. 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.join.namingstrategy; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.SecondaryTable; +import java.io.Serializable; + +/** + * @author Sergey Vasilyev + */ +@Entity +@SecondaryTable(name = "ExtendedLife") +public class Life implements Serializable { + @Id + @GeneratedValue + public Integer id; + + public int duration; + @Column(table = "ExtendedLife") + public String fullDescription; + + @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinColumn(name = "CAT_ID", table = "ExtendedLife") + public SimpleCat owner; + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/NamingStrategyJoinTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/NamingStrategyJoinTest.java new file mode 100644 index 0000000000..4aab52fde5 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/NamingStrategyJoinTest.java @@ -0,0 +1,66 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. 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.join.namingstrategy; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.cfg.Configuration; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; + +/** + * @author Sergey Vasilyev + */ +public class NamingStrategyJoinTest extends BaseCoreFunctionalTestCase { + @Override + public void configure(Configuration cfg) { + super.configure( cfg ); + cfg.setNamingStrategy( new TestNamingStrategy() ); + } + + + @Test + public void testJoinToSecondaryTable() throws Exception { + Session s = openSession(); + Transaction tx = s.beginTransaction(); + Life life = new Life(); + life.duration = 15; + life.fullDescription = "Long long description"; + s.persist( life ); + tx.commit(); + s.close(); + + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + Life.class, + SimpleCat.class + }; + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/SimpleCat.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/SimpleCat.java new file mode 100644 index 0000000000..97754b35ba --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/SimpleCat.java @@ -0,0 +1,58 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. 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.join.namingstrategy; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import java.io.Serializable; + +/** + * @author Sergey Vasilyev + */ +@Entity +public class SimpleCat implements Serializable { + private Integer id; + private String name; + + @Id + @GeneratedValue + public Integer getId() { + return id; + } + + public String getName() { + return name; + } + + public void setId(Integer integer) { + id = integer; + } + + public void setName(String string) { + name = string; + } + + +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/TestNamingStrategy.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/TestNamingStrategy.java new file mode 100644 index 0000000000..28fc76fda5 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/namingstrategy/TestNamingStrategy.java @@ -0,0 +1,36 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2011, Red Hat Inc. 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.join.namingstrategy; + +import org.hibernate.cfg.DefaultNamingStrategy; + +/** + * @author Sergey Vasilyev + */ +public class TestNamingStrategy extends DefaultNamingStrategy { + @Override + public String tableName(String tableName) { + return "TAB_" + tableName; + } +}