Author: sharathjreddy
Date: 2010-07-04 13:35:41 -0400 (Sun, 04 Jul 2010)
New Revision: 19893
Added:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Account.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Client.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Person.java
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java
Log:
HHH-4250 : @ManyToOne - @OneToMany doesn't work with @Inheritance(strategy=
InheritanceType.JOINED)
Added:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Account.java
===================================================================
---
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Account.java
(rev 0)
+++
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Account.java 2010-07-04
17:35:41 UTC (rev 19893)
@@ -0,0 +1,106 @@
+/*
+ * 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.inheritance.joined;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "ACCOUNT")
+public class Account implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private int id;
+
+ private String number;
+
+ @OneToMany(mappedBy="account")
+ private Set<Client> clients;
+
+ private double balance;
+
+ public Account() {
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ @SuppressWarnings("unused")
+ private void setId(int id) {
+ this.id = id;
+ }
+
+ public String getNumber() {
+ return this.number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+
+ public double getBalance() {
+ return balance;
+ }
+
+ public void setBalance(double balance) {
+ this.balance = balance;
+ }
+
+ public void addClient(Client c) {
+ if (clients == null) {
+ clients = new HashSet<Client>();
+ }
+ clients.add(c);
+ c.setAccount(this);
+ }
+
+
+ public Set<Client> getClients() {
+ return clients;
+ }
+
+ public void setClients(Set<Client> clients) {
+ this.clients = clients;
+ }
+
+
+
+
+
+}
Added:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Client.java
===================================================================
---
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Client.java
(rev 0)
+++
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Client.java 2010-07-04
17:35:41 UTC (rev 19893)
@@ -0,0 +1,93 @@
+/*
+ * 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.inheritance.joined;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "CLIENT")
+public class Client extends Person implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String street;
+
+ private String code;
+
+ private String city;
+
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinTable(name = "CLIENT_ACCOUNT",
+ joinColumns = {@JoinColumn(name = "FK_CLIENT", referencedColumnName =
"ID")},
+ inverseJoinColumns = {@JoinColumn(name = "FK_ACCOUNT", referencedColumnName
= "ID")})
+ private Account account;
+
+
+
+ public Account getAccount() {
+ return account;
+ }
+
+ public void setAccount(Account account) {
+ this.account = account;
+ }
+
+ public Client() {
+ super();
+ }
+
+ public String getStreet() {
+ return street;
+ }
+
+ public void setStreet(String street) {
+ this.street = street;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+}
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java
===================================================================
---
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java 2010-07-04
17:33:25 UTC (rev 19892)
+++
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java 2010-07-04
17:35:41 UTC (rev 19893)
@@ -1,7 +1,9 @@
//$Id$
package org.hibernate.test.annotations.inheritance.joined;
+import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.hibernate.Session;
import org.hibernate.Transaction;
@@ -122,7 +124,49 @@
transaction.commit();
session.close();
}
+
+ //HHH-4250 : @ManyToOne - @OneToMany doesn't work with @Inheritance(strategy=
InheritanceType.JOINED)
+ public void testManyToOneWithJoinTable() {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+
+ Client c1 = new Client();
+ c1.setFirstname("Firstname1");
+ c1.setName("Name1");
+ c1.setCode("1234");
+ c1.setStreet("Street1");
+ c1.setCity("City1");
+
+ Account a1 = new Account();
+ a1.setNumber("1000");
+ a1.setBalance(5000.0);
+
+ a1.addClient(c1);
+
+ s.persist(c1);
+ s.persist(a1);
+
+ s.flush();
+ s.clear();
+
+ c1 = (Client) s.load(Client.class, c1.getId());
+ assertEquals(5000.0, c1.getAccount().getBalance());
+
+ s.flush();
+ s.clear();
+
+ a1 = (Account) s.load(Account.class,a1.getId());
+ Set<Client> clients = a1.getClients();
+ assertEquals(1, clients.size());
+ Iterator<Client> it = clients.iterator();
+ c1 = it.next();
+ assertEquals("Name1", c1.getName());
+
+ tx.rollback();
+ s.close();
+ }
+
// public void testManyToOneAndJoin() throws Exception {
// Session session = openSession();
// Transaction transaction = session.beginTransaction();
@@ -168,6 +212,8 @@
Sweater.class,
EventInformation.class,
Alarm.class,
+ Client.class,
+ Account.class
//Asset.class,
//Parent.class,
//PropertyAsset.class,
Added:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Person.java
===================================================================
---
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Person.java
(rev 0)
+++
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Person.java 2010-07-04
17:35:41 UTC (rev 19893)
@@ -0,0 +1,80 @@
+/*
+ * 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.inheritance.joined;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+@Entity
+@Inheritance(strategy = InheritanceType.JOINED)
+@Table(name = "PERSON")
+public class Person {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private int id;
+
+ private String name;
+
+ private String firtsname;
+
+ public Person() {
+
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getFirstname() {
+ return firtsname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firtsname = firstname;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+}
+