-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Integer columns return null
PostPosted: Mon May 30, 2005 7:27 am 
Newbie

Joined: Tue May 24, 2005 6:51 am
Posts: 5
Hi all,

I'm having some trouble with Integer columns in related objects. I have Databases (PK is databaseID) and Table (PK is tableID) associated with an association table called TableInDatabase (PK is databaseID, tableID). then I map source and target database tables using a table called TableTarget (class TableMapper) which holds a set of keys from TableInDatabase per mapping (PK is sourceDatabaseID, sourceTableID, targetDatabseID, targetTableID).

I load up a list of TableMapper from the TableTarget database and get nulls for the tableIDs (databaseIDs are fine as are any other columns in the Tables table).

I've tried using fetch in the HQL (see the HibernateTableMapperDao below) as follows:

Code:
from TableMapper t left join fetch t.source right join fetch t.target
where t.source.database.id=? and t.target.database.id=?


All help appreciated! Details follow:

Hibernate version: 3.0.1

Class Files:

I changed the attributes to protected on the recommendation of somone on the Spring forum but it did not help. All getters and setters are public.

Table.class
Code:
public class Table extends AbstractModelObject {
   
    protected Integer id;
   
    protected String name;

    protected String schema;

   // Using List as opposed to Set because Velocity works better with List than Set
    protected List columns = new ArrayList();

   // Using List as opposed to Set because Velocity works better with List than Set
    protected List primaryKeyColumns = new ArrayList();

    protected Boolean hasFloats;

    protected List databases = new ArrayList();
   
    protected Integer version;


TableInDatabase.class
Code:
public class TableInDatabase extends AbstractModelObject {

    protected TableInDatabaseId compositeId;

    protected Database database = new Database();

    protected Table table = new Table();

    protected String insertConflictFlag;



TableInDatabaseID.class
Code:
public class TableInDatabaseId implements Serializable {

    protected Integer databaseId;

    protected Integer tableId;


TableMapper.class
Code:
public class TableMapper extends AbstractModelObject {

    protected TableMapperId compositeId;
   
    protected TableInDatabase source = new TableInDatabase();
   
    protected TableInDatabase target = new TableInDatabase();



TableMapperID.class
Code:
public class TableMapperId implements Serializable {

    protected Integer sourceDatabaseId;
   
    protected Integer sourceTableId;

    protected Integer targetDatabaseId;
   
    protected Integer targetTableId;
   


Mapping documents:
Table.class
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="za.co.telkom.ubr.model.Table"
        table="ReplTables"
    >

        <id
            name="id"
            column="TableId"
            type="int"
            unsaved-value="-1"
        >
            <generator class="native">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-Table.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="TableName"
            length="64"
            not-null="true"
        />

        <property
            name="schema"
            type="java.lang.String"
            update="true"
            insert="true"
            column="SchemaName"
            length="64"
            not-null="false"
        />

        <bag
            name="columns"
            lazy="true"
            inverse="true"
            cascade="all"
            order-by="Sequence"
        >

            <key
                column="TableId"
            >
            </key>

            <one-to-many
                  class="za.co.telkom.ubr.model.Column"
            />

      </bag>

        <property
            name="hasFloats"
            type="boolean"
            update="true"
            insert="true"
            column="HasFloatColumns"
            not-null="false"
        />

        <bag
            name="databases"
            lazy="true"
            inverse="true"
            cascade="all"
            order-by="DatabaseId"
        >

            <key
                column="TableId"
            >
            </key>

            <one-to-many
                  class="za.co.telkom.ubr.model.TableInDatabase"
            />

      </bag>

        <property
            name="version"
            type="java.lang.Integer"
            update="true"
            insert="true"
            column="Version"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Table.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


TableInDatabase.class:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="za.co.telkom.ubr.model.TableInDatabase"
        table="ReplTableInDatabase"
    >

        <composite-id
            name="compositeId"
            class="za.co.telkom.ubr.model.TableInDatabaseId"
        >
                     <key-property
                        name="databaseId"
                        type="java.lang.Integer"
                        column="DatabaseId"
                />

                     <key-property
                        name="tableId"
                        type="java.lang.Integer"
                        column="TableId"
                />

        </composite-id>

        <many-to-one
            name="database"
            class="za.co.telkom.ubr.model.Database"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
            column="DatabaseId"
            not-null="true"
        />

        <many-to-one
            name="table"
            class="za.co.telkom.ubr.model.Table"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
            column="TableId"
            not-null="true"
        />

        <property
            name="insertConflictFlag"
            type="java.lang.String"
            update="true"
            insert="true"
            column="InsertConflictFlag"
            length="1"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-TableInDatabase.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>


TableMapper.class:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
    <class
        name="za.co.telkom.ubr.model.TableMapper"
        table="ReplTableTarget"
    >

        <composite-id
            name="compositeId"
            class="za.co.telkom.ubr.model.TableMapperId"
        >
                     <key-property
                        name="sourceDatabaseId"
                        type="java.lang.Integer"
                        column="SourceDatabaseId"
                />

                     <key-property
                        name="sourceTableId"
                        type="java.lang.Integer"
                        column="SourceTableId"
                />

                     <key-property
                        name="targetDatabaseId"
                        type="java.lang.Integer"
                        column="TargetDatabaseId"
                />

                     <key-property
                        name="targetTableId"
                        type="java.lang.Integer"
                        column="TargetTableId"
                />

        </composite-id>

        <many-to-one
            name="source"
            class="za.co.telkom.ubr.model.TableInDatabase"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
        >
            <column
                name="SourceDatabaseId"
            />
            <column
                name="SourceTableId"
            />
        </many-to-one>

        <many-to-one
            name="target"
            class="za.co.telkom.ubr.model.TableInDatabase"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
        >
            <column
                name="TargetDatabaseId"
            />
            <column
                name="TargetTableId"
            />
        </many-to-one>

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-TableMapper.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
I'm using Hibernate within Spring ( getHibernateTemplate().find("...") )

DAO code:
Code:
public class HibernateTableMapperDao extends HibernateGenericDao implements TableMapperDao {

    /* (non-Javadoc)
     * @see za.co.telkom.ubr.dao.TableMapperDao#findTargetTable(java.lang.Integer)
     */
    public List findTableMapper(Integer databaseId)
            throws ObjectRetrievalFailureException {
       
        List objects = getHibernateTemplate().find(
                "from TableMapper t where t.source.database.id=?", databaseId);

      return objects;
    }

    /* (non-Javadoc)
     * @see za.co.telkom.ubr.dao.TableMapperDao#loadTableMappers(java.lang.Integer, java.lang.Integer)
     */
    public List loadTableMappers(Integer sourceDatabaseId, Integer targetDatabaseId)
            throws ObjectRetrievalFailureException {

        Integer[] values = {sourceDatabaseId, targetDatabaseId};
        List objects = getHibernateTemplate().find(
                "from TableMapper t where t.source.database.id=? and t.target.database.id=?", values);

[color=red]// These statements all return null for the TableID columns[/color]
logger.debug("***** loaded object tableId ["+((TableMapper)(objects.get(0))).getCompositeId().getSourceTableId()+"]");
logger.debug("***** loaded object tableId ["+((TableMapper)(objects.get(0))).getSource().getTable().getId()+"]");
logger.debug("***** table name = ["+((TableMapper)(objects.get(0))).getSource().getTable().getName()+"]");
        return objects;
    }

}




Name and version of the database you are using: MySQL 4.0.18

The generated SQL (show_sql=true) and log excerpt:
Look for **** demarking debug output below:

    Hibernate: select table0_.TableId as TableId0_, table0_.TableName as TableName16_0_, table0_.SchemaName as SchemaName16_0_, table0_.HasFloatColumns as HasFloat4_16_0_, table0_.Version as Version16_0_ from ReplTables table0_ where table0_.TableId=?
    Hibernate: select columns0_.TableId as TableId__, columns0_.ColumnId as ColumnId__, columns0_.ColumnId as ColumnId0_, columns0_.version as version17_0_, columns0_.ColumnName as ColumnName17_0_, columns0_.SQLDataType as SQLDataT4_17_0_, columns0_.CDataType as CDataType17_0_, columns0_.Attributes as Attributes17_0_, columns0_.Sequence as Sequence17_0_, columns0_.MaxTextWidth as MaxTextW8_17_0_, columns0_.IsPrimaryKey as IsPrimar9_17_0_, columns0_.IsNullAllowed as IsNullA10_17_0_, columns0_.TransformPrefix as Transfo11_17_0_, columns0_.TransformSuffix as Transfo12_17_0_, columns0_.TableId as TableId17_0_ from ReplColumns columns0_ where columns0_.TableId=? order by columns0_.Sequence
    Hibernate: select table0_.TableId as TableId0_, table0_.TableName as TableName16_0_, table0_.SchemaName as SchemaName16_0_, table0_.HasFloatColumns as HasFloat4_16_0_, table0_.Version as Version16_0_ from ReplTables table0_ where table0_.TableId=?
    Hibernate: select columns0_.TableId as TableId__, columns0_.ColumnId as ColumnId__, columns0_.ColumnId as ColumnId0_, columns0_.version as version17_0_, columns0_.ColumnName as ColumnName17_0_, columns0_.SQLDataType as SQLDataT4_17_0_, columns0_.CDataType as CDataType17_0_, columns0_.Attributes as Attributes17_0_, columns0_.Sequence as Sequence17_0_, columns0_.MaxTextWidth as MaxTextW8_17_0_, columns0_.IsPrimaryKey as IsPrimar9_17_0_, columns0_.IsNullAllowed as IsNullA10_17_0_, columns0_.TransformPrefix as Transfo11_17_0_, columns0_.TransformSuffix as Transfo12_17_0_, columns0_.TableId as TableId17_0_ from ReplColumns columns0_ where columns0_.TableId=? order by columns0_.Sequence
    Hibernate: select database0_.DatabaseId as DatabaseId0_, database0_.version as version13_0_, database0_.DatabaseName as Database3_13_0_, database0_.DBMSServerName as DBMSServ4_13_0_, database0_.DBMSServerConnect as DBMSServ5_13_0_, database0_.DBMSId as DBMSId13_0_ from ReplDatabases database0_ where database0_.DatabaseId=?
    Hibernate: select tables0_.DatabaseId as DatabaseId__, tables0_.TableId as TableId__, tables0_.DatabaseId as DatabaseId0_, tables0_.TableId as TableId0_, tables0_.DatabaseId as DatabaseId18_0_, tables0_.TableId as TableId18_0_, tables0_.InsertConflictFlag as InsertCo3_18_0_ from ReplTableInDatabase tables0_ where tables0_.DatabaseId=? order by tables0_.TableId
    Hibernate: select database0_.DatabaseId as DatabaseId0_, database0_.version as version13_0_, database0_.DatabaseName as Database3_13_0_, database0_.DBMSServerName as DBMSServ4_13_0_, database0_.DBMSServerConnect as DBMSServ5_13_0_, database0_.DBMSId as DBMSId13_0_ from ReplDatabases database0_ where database0_.DatabaseId=?
    Hibernate: select tables0_.DatabaseId as DatabaseId__, tables0_.TableId as TableId__, tables0_.DatabaseId as DatabaseId0_, tables0_.TableId as TableId0_, tables0_.DatabaseId as DatabaseId18_0_, tables0_.TableId as TableId18_0_, tables0_.InsertConflictFlag as InsertCo3_18_0_ from ReplTableInDatabase tables0_ where tables0_.DatabaseId=? order by tables0_.TableId
    Hibernate: select tablemappe0_.SourceDatabaseId as SourceDa1_0_, tablemappe0_.SourceTableId as SourceTa2_0_, tablemappe0_.TargetDatabaseId as TargetDa3_0_, tablemappe0_.TargetTableId as TargetTa4_0_, tableindat1_.DatabaseId as DatabaseId1_, tableindat1_.TableId as TableId1_, tableindat2_.DatabaseId as DatabaseId2_, tableindat2_.TableId as TableId2_, tablemappe0_.SourceDatabaseId as SourceDa1_19_0_, tablemappe0_.SourceTableId as SourceTa2_19_0_, tablemappe0_.TargetDatabaseId as TargetDa3_19_0_, tablemappe0_.TargetTableId as TargetTa4_19_0_, tableindat1_.DatabaseId as DatabaseId18_1_, tableindat1_.TableId as TableId18_1_, tableindat1_.InsertConflictFlag as InsertCo3_18_1_, tableindat2_.DatabaseId as DatabaseId18_2_, tableindat2_.TableId as TableId18_2_, tableindat2_.InsertConflictFlag as InsertCo3_18_2_ from ReplTableTarget tablemappe0_ left outer join ReplTableInDatabase tableindat1_ on tablemappe0_.SourceDatabaseId=tableindat1_.DatabaseId and tablemappe0_.SourceTableId=tableindat1_.TableId right outer join ReplTableInDatabase tableindat2_ on tablemappe0_.TargetDatabaseId=tableindat2_.DatabaseId and tablemappe0_.TargetTableId=tableindat2_.TableId where (tableindat1_.DatabaseId=? and tableindat2_.DatabaseId=?)
    Hibernate: select tableindat0_.DatabaseId as DatabaseId0_, tableindat0_.TableId as TableId0_, tableindat0_.DatabaseId as DatabaseId18_0_, tableindat0_.TableId as TableId18_0_, tableindat0_.InsertConflictFlag as InsertCo3_18_0_ from ReplTableInDatabase tableindat0_ where tableindat0_.DatabaseId=? and tableindat0_.TableId=?
    [replconsole] 2005-05-30 12:51:45,206 DEBUG [za.co.telkom.ubr.dao.hibernate.HibernateTableMapperDao] - <***** loaded object tableId [-1]>
    [replconsole] 2005-05-30 12:51:45,206 DEBUG [za.co.telkom.ubr.dao.hibernate.HibernateTableMapperDao] - <***** loaded object tableId [-1]>
    [replconsole] 2005-05-30 12:51:45,206 DEBUG [za.co.telkom.ubr.controller.MappingController] - <**** source and target table IDs [-1] [-1]>
    Hibernate: select table0_.TableId as TableId0_, table0_.TableName as TableName16_0_, table0_.SchemaName as SchemaName16_0_, table0_.HasFloatColumns as HasFloat4_16_0_, table0_.Version as Version16_0_ from ReplTables table0_ where table0_.TableId=?
    Hibernate: select columns0_.TableId as TableId__, columns0_.ColumnId as ColumnId__, columns0_.ColumnId as ColumnId0_, columns0_.version as version17_0_, columns0_.ColumnName as ColumnName17_0_, columns0_.SQLDataType as SQLDataT4_17_0_, columns0_.CDataType as CDataType17_0_, columns0_.Attributes as Attributes17_0_, columns0_.Sequence as Sequence17_0_, columns0_.MaxTextWidth as MaxTextW8_17_0_, columns0_.IsPrimaryKey as IsPrimar9_17_0_, columns0_.IsNullAllowed as IsNullA10_17_0_, columns0_.TransformPrefix as Transfo11_17_0_, columns0_.TransformSuffix as Transfo12_17_0_, columns0_.TableId as TableId17_0_ from ReplColumns columns0_ where columns0_.TableId=? order by columns0_.Sequence


Kind regards,
Stefan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.