HHH-5732 - @OrderColumn not updated if @OneToMany has mappedby defined
This commit is contained in:
parent
23f49f19b5
commit
624855c438
|
@ -22,14 +22,28 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.test.collection.list;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.collection.internal.PersistentList;
|
||||
import org.hibernate.jdbc.Work;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.collection.QueryableCollection;
|
||||
import org.hibernate.sql.SimpleSelect;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -44,6 +58,68 @@ public class PersistentListTest extends BaseCoreFunctionalTestCase {
|
|||
return new String[] { "collection/list/Mappings.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-5732" )
|
||||
@FailureExpected( jiraKey = "HHH-5732" )
|
||||
public void testInverseListIndexColumnWritten() {
|
||||
// make sure no one changes the mapping
|
||||
final CollectionPersister collectionPersister = sessionFactory().getCollectionPersister( ListOwner.class.getName() + ".children" );
|
||||
assertTrue( collectionPersister.isInverse() );
|
||||
|
||||
// do some creations...
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
|
||||
ListOwner root = new ListOwner( "root" );
|
||||
ListOwner child1 = new ListOwner( "c1" );
|
||||
root.getChildren().add( child1 );
|
||||
child1.setParent( root );
|
||||
ListOwner child2 = new ListOwner( "c2" );
|
||||
root.getChildren().add( child2 );
|
||||
child2.setParent( root );
|
||||
|
||||
session.save( root );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
// now, make sure the list-index column gotten written...
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
session.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( "NAME" )
|
||||
.addColumn( "LIST_INDEX" )
|
||||
.addCondition( "NAME", "<>", "?" );
|
||||
PreparedStatement preparedStatement = connection.prepareStatement( select.toStatementString() );
|
||||
preparedStatement.setString( 1, "root" );
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
Map<String, Integer> valueMap = new HashMap<String, Integer>();
|
||||
while ( resultSet.next() ) {
|
||||
final String name = resultSet.getString( 1 );
|
||||
assertFalse( "NAME column was null", resultSet.wasNull() );
|
||||
final int position = resultSet.getInt( 2 );
|
||||
assertFalse( "LIST_INDEX column was null", resultSet.wasNull() );
|
||||
valueMap.put( name, position );
|
||||
}
|
||||
assertEquals( 2, valueMap.size() );
|
||||
|
||||
// c1 should be list index 0
|
||||
assertEquals( Integer.valueOf( 0 ), valueMap.get( "c1" ) );
|
||||
// c2 should be list index 1
|
||||
assertEquals( Integer.valueOf( 1 ), valueMap.get( "c2" ) );
|
||||
}
|
||||
}
|
||||
);
|
||||
session.delete( root );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteMethodDirtying() {
|
||||
ListOwner parent = new ListOwner( "root" );
|
||||
|
|
Loading…
Reference in New Issue