Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
HHH-9597 : Criteria creates invalid column aliases (test case)
(cherry picked from commit c9df758)
  • Loading branch information
gbadner committed Feb 12, 2015
1 parent f191bf8 commit b4f3a87
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 12 deletions.
@@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, 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.criteria;

/**
* @author Gail Badner
*/
public class Address {
private int addressId;

public int getAddressId() {
return addressId;
}

private String addressText;

public String getAddressText() {
return addressText;
}

public void setAddressText(String addressText) {
this.addressText = addressText;
}
}
Expand Up @@ -6,10 +6,15 @@
<id name="orderId" column="order_id" type="int" unsaved-value="0" access="field" >
<generator class="increment" />
</id>
<many-to-one name="orderAddress" cascade="all"/>
<set name="orderLines" cascade="all-delete-orphan" access="field" inverse="true" fetch="select">
<key column="order_id" />
<one-to-many class="OrderLine" />
</set>
<set name="orderContacts" cascade="all-delete-orphan" access="field" fetch="select">
<key column="order_id" />
<many-to-many class="OrderContact" />
</set>
</class>
<class name="OrderLine" table="order_line">
<id name="lineId" column="order_line_id" type="int" unsaved-value="0" access="field" >
Expand All @@ -18,5 +23,31 @@
<many-to-one name="order" column="order_id" class="Order" />
<property name="articleId" column="article_id" type="string" />
</class>
<class name="OrderContact" table="order_contact">
<id name="contactId" column="order_contact_id" type="int" unsaved-value="0" access="field" >
<generator class="increment" />
</id>
<property name="contact" column="contact" type="string" />
<set name="orders" access="field" inverse="true" fetch="select">
<key column="contact_id" />
<many-to-many class="Order" />
</set>
</class>
<class name="OrderAddress">
<id name="orderAddressId" type="int" unsaved-value="0" access="field" >
<generator class="increment" />
</id>
<many-to-one name="deliveryAddress" class="Address" cascade="all" />
<set name="notifiedAddresses" cascade="all" inverse="false" fetch="select" >
<key column="orderAddressId"/>
<one-to-many class="Address"/>
</set>
</class>
<class name="Address">
<id name="addressId" column="address_id" type="int" unsaved-value="0" access="field" >
<generator class="increment" />
</id>
<property name="addressText"/>
</class>
</hibernate-mapping>

43 changes: 32 additions & 11 deletions hibernate-core/src/test/java/org/hibernate/test/criteria/Order.java
Expand Up @@ -29,24 +29,45 @@

public class Order {

private int orderId;
private int orderId;

public int getOrderId() {
public int getOrderId() {
return orderId;
}

private Set<OrderLine> orderLines = new HashSet<OrderLine>();
private Set<OrderLine> orderLines = new HashSet<OrderLine>();

public Set<OrderLine> getLines() {
public Set<OrderLine> getLines() {
return Collections.unmodifiableSet(orderLines);
}

public void addLine(OrderLine orderLine){
orderLine.setOrder(this);
this.orderLines.add(orderLine);
}

public String toString() {
public void addLine(OrderLine orderLine){
orderLine.setOrder(this);
this.orderLines.add(orderLine);
}

private Set<OrderContact> orderContacts = new HashSet<OrderContact>();

public Set<OrderContact> getContacts() {
return Collections.unmodifiableSet(orderContacts);
}

public void addContact(OrderContact orderContact){
orderContact.getOrders().add( this );
this.orderContacts.add(orderContact);
}

public OrderAddress orderAddress;

public OrderAddress getOrderAddress() {
return orderAddress;
}

public void setOrderAddress(OrderAddress orderAddress) {
this.orderAddress = orderAddress;
}

public String toString() {
return "" + getOrderId() + " - " + getLines();
}
}
}
@@ -0,0 +1,60 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2015, 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.criteria;

import java.util.HashSet;
import java.util.Set;

public class OrderAddress {

private int orderAddressId;

public int getOrderAddressId() {
return orderAddressId;
}

private Address deliveryAddress;

public Address getDeliveryAddress() {
return deliveryAddress;
}

public void setDeliveryAddress(Address deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}

private Set<Address> notifiedAddresses = new HashSet<Address>();

public Set<Address> getNotifiedAddresses() {
return notifiedAddresses;
}

public void setNotifiedAddresses(Set<Address> notifiedAddresses) {
this.notifiedAddresses = notifiedAddresses;
}

public String toString() {
return "" + orderAddressId + " - " + getDeliveryAddress() + " - " + getNotifiedAddresses();
}
}
@@ -0,0 +1,56 @@
/*
* 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.criteria;

import java.util.HashSet;
import java.util.Set;

public class OrderContact {

private int contactId = 0;
private Set<Order> orders = new HashSet<Order>();

private String contact;


public int getContactId() {
return contactId;
}

public Set<Order> getOrders() {
return orders;
}

public String getContact() {
return contact;
}

public void setContact(String contact) {
this.contact = contact;
}

public String toString() {
return "[" + getContactId() + ":" + getContact() + "]";
}
}

0 comments on commit b4f3a87

Please sign in to comment.