HHH-5732 - @OrderColumn not updated if @OneToMany has mappedby defined
This commit is contained in:
parent
98c12081ec
commit
139474624f
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, 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.collection.list;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class LineItem {
|
||||||
|
private Integer id;
|
||||||
|
private Order order;
|
||||||
|
private String productCode;
|
||||||
|
private BigDecimal costPer;
|
||||||
|
private int quantity;
|
||||||
|
|
||||||
|
public LineItem() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public LineItem(Order order, String productCode, int quantity, BigDecimal costPer) {
|
||||||
|
this.order = order;
|
||||||
|
this.productCode = productCode;
|
||||||
|
this.quantity = quantity;
|
||||||
|
this.costPer = costPer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(Order order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProductCode() {
|
||||||
|
return productCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductCode(String productCode) {
|
||||||
|
this.productCode = productCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getCostPer() {
|
||||||
|
return costPer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCostPer(BigDecimal costPer) {
|
||||||
|
this.costPer = costPer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getQuantity() {
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantity(int quantity) {
|
||||||
|
this.quantity = quantity;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,4 +18,26 @@
|
||||||
</list>
|
</list>
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
|
<class name="Order" table="T_ORDER">
|
||||||
|
<id name="id" column="id" type="integer">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
<property name="code" column="code" type="string"/>
|
||||||
|
<list name="lineItems" inverse="true" cascade="all">
|
||||||
|
<key column="order_id" />
|
||||||
|
<list-index column="INDX"/>
|
||||||
|
<one-to-many class="LineItem" />
|
||||||
|
</list>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
<class name="LineItem" table="T_LINE_ITEM">
|
||||||
|
<id name="id" column="id" type="integer">
|
||||||
|
<generator class="increment"/>
|
||||||
|
</id>
|
||||||
|
<many-to-one name="order" class="Order" column="order_id" cascade="all"/>
|
||||||
|
<property name="productCode" column="PRD_CODE" type="string"/>
|
||||||
|
<property name="quantity" column="qty" type="integer"/>
|
||||||
|
<property name="costPer" column="cost_per" type="big_decimal"/>
|
||||||
|
</class>
|
||||||
|
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, 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.collection.list;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public class Order {
|
||||||
|
private Integer id;
|
||||||
|
private String code;
|
||||||
|
private List<LineItem> lineItems = new ArrayList<LineItem>();
|
||||||
|
|
||||||
|
public Order() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<LineItem> getLineItems() {
|
||||||
|
return lineItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLineItems(List<LineItem> lineItems) {
|
||||||
|
this.lineItems = lineItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LineItem addLineItem(String productCode, int quantity, BigDecimal costPer) {
|
||||||
|
LineItem lineItem = new LineItem( this, productCode, quantity, costPer );
|
||||||
|
lineItems.add( lineItem );
|
||||||
|
return lineItem;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
@ -120,6 +121,63 @@ public class PersistentListTest extends BaseCoreFunctionalTestCase {
|
||||||
session2.close();
|
session2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestForIssue( jiraKey = "HHH-5732" )
|
||||||
|
@FailureExpected( jiraKey = "HHH-5732" )
|
||||||
|
public void testInverseListIndexColumnWritten2() {
|
||||||
|
// make sure no one changes the mapping
|
||||||
|
final CollectionPersister collectionPersister = sessionFactory().getCollectionPersister( Order.class.getName() + ".lineItems" );
|
||||||
|
assertTrue( collectionPersister.isInverse() );
|
||||||
|
|
||||||
|
// do some creations...
|
||||||
|
Session session = openSession();
|
||||||
|
session.beginTransaction();
|
||||||
|
|
||||||
|
Order order = new Order( "acme-1" );
|
||||||
|
order.addLineItem( "abc", 2, new BigDecimal( 16.1 ) );
|
||||||
|
order.addLineItem( "def", 200, new BigDecimal( .01 ) );
|
||||||
|
order.addLineItem( "ghi", 13, new BigDecimal( 12.9 ) );
|
||||||
|
session.save( order );
|
||||||
|
session.getTransaction().commit();
|
||||||
|
session.close();
|
||||||
|
|
||||||
|
// now, make sure the list-index column gotten written...
|
||||||
|
final Session session2 = openSession();
|
||||||
|
session2.beginTransaction();
|
||||||
|
session2.doWork(
|
||||||
|
new Work() {
|
||||||
|
@Override
|
||||||
|
public void execute(Connection connection) throws SQLException {
|
||||||
|
final QueryableCollection queryableCollection = (QueryableCollection) collectionPersister;
|
||||||
|
SimpleSelect select = new SimpleSelect( getDialect() )
|
||||||
|
.setTableName( queryableCollection.getTableName() )
|
||||||
|
.addColumn( "ORDER_ID" )
|
||||||
|
.addColumn( "INDX" )
|
||||||
|
.addColumn( "PRD_CODE" );
|
||||||
|
PreparedStatement preparedStatement = ((SessionImplementor)session2).getTransactionCoordinator().getJdbcCoordinator().getStatementPreparer().prepareStatement( select.toStatementString() );
|
||||||
|
ResultSet resultSet = ((SessionImplementor)session2).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( preparedStatement );
|
||||||
|
Map<String, Integer> valueMap = new HashMap<String, Integer>();
|
||||||
|
while ( resultSet.next() ) {
|
||||||
|
final int fk = resultSet.getInt( 1 );
|
||||||
|
assertFalse( "Collection key (FK) column was null", resultSet.wasNull() );
|
||||||
|
final int indx = resultSet.getInt( 2 );
|
||||||
|
assertFalse( "List index column was null", resultSet.wasNull() );
|
||||||
|
final String prodCode = resultSet.getString( 3 );
|
||||||
|
assertFalse( "Prod code column was null", resultSet.wasNull() );
|
||||||
|
valueMap.put( prodCode, indx );
|
||||||
|
}
|
||||||
|
assertEquals( 3, valueMap.size() );
|
||||||
|
assertEquals( Integer.valueOf( 0 ), valueMap.get( "abc" ) );
|
||||||
|
assertEquals( Integer.valueOf( 1 ), valueMap.get( "def" ) );
|
||||||
|
assertEquals( Integer.valueOf( 2 ), valueMap.get( "ghi" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
session2.delete( order );
|
||||||
|
session2.getTransaction().commit();
|
||||||
|
session2.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteMethodDirtying() {
|
public void testWriteMethodDirtying() {
|
||||||
ListOwner parent = new ListOwner( "root" );
|
ListOwner parent = new ListOwner( "root" );
|
||||||
|
|
Loading…
Reference in New Issue