@Test public void testRevEntityTableCreation() { for ( Table table : metadata().collectTableMappings() ) { if ( "REVCHANGES".equals( table.getName() ) ) { assert table.getColumnSpan() == 2; assert table.getColumn( new Column( "REV" ) ) != null; assert table.getColumn( new Column( "ENTITYNAME" ) ) != null; return; } } assert false; }
private void assertSameTableUsed(Metadata metadata) { Collection inputs1Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs1" ); assertEquals( "ptx_input", inputs1Mapping.getCollectionTable().getName() ); Collection inputs2Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs2" ); assertEquals( "ptx_input", inputs2Mapping.getCollectionTable().getName() ); assertSame( inputs1Mapping.getCollectionTable(), inputs2Mapping.getCollectionTable() ); // NOTE : here so that tester can more easily see the produced table. It is only dumped to stdout new SchemaExport().create( EnumSet.of( TargetType.STDOUT ), metadata ); for ( int i = 0; i < inputs1Mapping.getCollectionTable().getColumnSpan(); i++ ) { final Column column = inputs1Mapping.getCollectionTable().getColumn( i ); // this, coupled with JPA saying the 2 collections implicitly map to the same table, // is the crux of the problem: all columns are null, so we effectively can never // insert rows into it. assertFalse( column.isNullable() ); } }
protected void checkDefaultJoinTableAndAllColumnNames( Metadata metadata, Class<?> ownerEntityClass, String ownerCollectionPropertyName, String expectedCollectionTableName, String ownerForeignKeyNameExpected, String[] columnNames) { final org.hibernate.mapping.Collection collection = metadata.getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); final org.hibernate.mapping.Table table = collection.getCollectionTable(); assertEquals( expectedCollectionTableName, table.getName() ); // The default owner and inverse join columns can only be computed if they have PK with 1 column. assertEquals( 1, collection.getOwner().getKey().getColumnSpan() ); assertEquals( ownerForeignKeyNameExpected, collection.getKey().getColumnIterator().next().getText() ); int columnNumber = table.getColumnSpan(); for ( int i = 0; i < columnNumber; i++ ) { assertEquals( columnNames[i], table.getColumn( i + 1 ).getName()); } }
if ( pk==null || pk.getColumns().size() != table.getColumnSpan() ) return false;
@Test public void testBasic() throws SQLException { Metadata metadata = MetadataDescriptorFactory .createJdbcDescriptor(null, null, true) .createMetadata(); JUnitUtil.assertIteratorContainsExactly( "There should be " + TABLECOUNT + " tables!", metadata.collectTableMappings().iterator(), TABLECOUNT); Table tab = (Table) metadata.collectTableMappings().iterator().next(); Assert.assertEquals(tab.getColumnSpan(), COLCOUNT+1); }
if ( pk==null || pk.getColumns().size() != table.getColumnSpan() ) return false;
@Test public void testBasic() throws SQLException { JUnitUtil.assertIteratorContainsExactly( "There should be 2 tables!", metadata.collectTableMappings().iterator(), 2); Table table = HibernateUtil.getTable(metadata, JdbcUtil.toIdentifier(this, "B_TAB" ) ); Table table2 = HibernateUtil.getTable(metadata, JdbcUtil.toIdentifier(this, "B2TAB" ) ); Assert.assertNotNull(table); Assert.assertNotNull(table2); Assert.assertEquals(table.getColumnSpan(), 2); Assert.assertEquals(table2.getColumnSpan(), 2); }
@Test public void testForQuotes() { Table table = HibernateUtil.getTable(metadata, "us-ers"); Assert.assertNotNull(table); Assert.assertTrue(table.isQuoted()); Assert.assertEquals(2, table.getColumnSpan()); PersistentClass classMapping = metadata.getEntityBinding("Worklogs"); Assert.assertNotNull(classMapping); Property property = classMapping.getProperty("usErs"); Assert.assertNotNull(property); }
table.setSchema(null); if(table.getColumnSpan()==0) { log.warn("Cannot create persistent class for " + table + " as no columns were found."); continue;
table.setSchema(null); if(table.getColumnSpan()==0) { log.warn("Cannot create persistent class for " + table + " as no columns were found."); continue;
@Test public void testBasic() throws SQLException { JUnitUtil.assertIteratorContainsExactly( "There should be three tables!", metadata.getEntityBindings().iterator(), 3); Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "BASIC")); Assert.assertEquals( JdbcUtil.toIdentifier(this, "BASIC"), JdbcUtil.toIdentifier(this, table.getName())); Assert.assertEquals(2, table.getColumnSpan()); Column basicColumn = table.getColumn(0); Assert.assertEquals( JdbcUtil.toIdentifier(this, "A"), JdbcUtil.toIdentifier(this, basicColumn.getName())); PrimaryKey key = table.getPrimaryKey(); Assert.assertNotNull("There should be a primary key!", key); Assert.assertEquals(key.getColumnSpan(), 1); Column column = key.getColumn(0); Assert.assertTrue(column.isUnique()); Assert.assertSame(basicColumn, column); }
@Test public void testBasic() throws SQLException { JUnitUtil.assertIteratorContainsExactly( "There should be three tables!", metadata.getEntityBindings().iterator(), 3); Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "BASIC" ) ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "BASIC"), JdbcUtil.toIdentifier(this, table.getName()) ); Assert.assertEquals( 2, table.getColumnSpan() ); Column basicColumn = table.getColumn( 0 ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "A"), JdbcUtil.toIdentifier(this, basicColumn.getName() )); // TODO: we cannot call getSqlType(dialect,cfg) without a // MappingassertEquals("INTEGER", basicColumn.getSqlType() ); // at // least on hsqldb // assertEquals(22, basicColumn.getLength() ); // at least on oracle PrimaryKey key = table.getPrimaryKey(); Assert.assertNotNull( "There should be a primary key!", key ); Assert.assertEquals( key.getColumnSpan(), 1 ); Column column = key.getColumn( 0 ); Assert.assertTrue( column.isUnique() ); Assert.assertSame( basicColumn, column ); }
@Test public void testBasic() { JUnitUtil.assertIteratorContainsExactly( "There should be three tables!", metadata.getEntityBindings().iterator(), 3); Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "BASIC" ) ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "BASIC"), JdbcUtil.toIdentifier(this, table.getName())); Assert.assertEquals( 2, table.getColumnSpan() ); Column basicColumn = table.getColumn( 0 ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "A"), JdbcUtil.toIdentifier(this, basicColumn.getName())); // TODO: we cannot call getSqlType(dialect,cfg) without a // MappingassertEquals("INTEGER", basicColumn.getSqlType() ); // at // least on hsqldb // assertEquals(22, basicColumn.getLength() ); // at least on oracle PrimaryKey key = table.getPrimaryKey(); Assert.assertNotNull( "There should be a primary key!", key ); Assert.assertEquals( key.getColumnSpan(), 1 ); Column column = key.getColumn( 0 ); Assert.assertTrue( column.isUnique() ); Assert.assertSame( basicColumn, column ); }