-->
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.  [ 6 posts ] 
Author Message
 Post subject: Tools Not recognizing composite ID from Ant task
PostPosted: Tue Aug 29, 2006 11:23 am 
Newbie

Joined: Fri Mar 24, 2006 11:46 am
Posts: 3
Hibernate version: 3.1.3
Hibernate Tools plugin version: 3.2.0.beta6a
Hibernate Tools ant task version: 3.2.0.beta7

Name and version of the database you are using: oracle 9.2.0.6.0

I'm switching from using the plug-in for the reverse to using the Ant Task but have run into a problem with getting the Ant Task reverse to recognize the composite ID in the same way as the plug-in.

As an example, here is the Oracle DDL for the table:

Code:
CREATE TABLE TDOCUMENT_FSI
(
  DOCUMENT_CODE         VARCHAR2(64 BYTE)       NOT NULL,
  ID_DOCUMENT_TYPE      NUMBER(10),
  ID_EVENT              NUMBER(10),
  STATUS                VARCHAR2(50 BYTE),
  DOCUMENT              BLOB                    NOT NULL,
  ID_APPLICATION        NUMBER(10),
  TRANSFORM_STATUS      VARCHAR2(2 BYTE)        DEFAULT ' '                   NOT NULL,
  DOCUMENT_SIZE         NUMBER(10),
  TRANSFORM_TECH_ERROR  CLOB,
  TRANSFORM_FUNC_ERROR  CLOB
)
/


CREATE UNIQUE INDEX PK_DOCUMENT_UNIQUE_KEY ON TDOCUMENT_FSI
(ID_EVENT, DOCUMENT_CODE, ID_DOCUMENT_TYPE)
/


The reveng for this table looks like:

Code:
<table name="TDOCUMENT_FSI" class="com.sgcib.fsi.fsio.hib.Document">
    <primary-key>
        <key-column name="ID_EVENT" property="eventId" />
        <key-column name="DOCUMENT_CODE" property="docCode" />
        <key-column name="ID_DOCUMENT_TYPE" property="docType" />
    </primary-key>
    <foreign-key constraint-name="FK_TDOCUMEN_APPLICATION">
        <many-to-one property="application"/>
        <set property="documents"/>
    </foreign-key>
    <foreign-key constraint-name="FK_TDOCUMEN_EVENT">
        <many-to-one property="event"/>
        <set property="documents"/>
    </foreign-key>
    <foreign-key constraint-name="FK_TDOCUMEN_DOCTYPE">
        <many-to-one property="docType"/>
    </foreign-key>
</table>


Running the plug-in produces this Document.hbm.xml:

Code:
<!-- Generated Aug 29, 2006 4:56:35 PM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="com.sgcib.fsi.fsio.hib.Document" table="TDOCUMENT_FSI">
        <composite-id name="id" class="com.sgcib.fsi.fsio.hib.DocumentId">
            <key-many-to-one name="event" class="com.sgcib.fsi.fsio.hib.TransformationEvent">
                <column name="ID_EVENT" precision="10" scale="0" />
            </key-many-to-one>
            <key-property name="docCode" type="string">
                <column name="DOCUMENT_CODE" length="64" />
            </key-property>
            <key-many-to-one name="docType" class="com.sgcib.fsi.fsio.hib.DocumentType">
                <column name="ID_DOCUMENT_TYPE" precision="10" scale="0" />
            </key-many-to-one>
        </composite-id>
        <many-to-one name="application" class="com.sgcib.fsi.fsio.hib.Application" fetch="select">
            <column name="ID_APPLICATION" precision="10" scale="0" />
        </many-to-one>
        <property name="status" type="string">
            <column name="STATUS" length="50" />
        </property>
        <property name="document" type="blob">
            <column name="DOCUMENT" not-null="true" />
        </property>
        <property name="transformStatus" type="string">
            <column name="TRANSFORM_STATUS" length="2" not-null="true" />
        </property>
        <property name="documentSize" type="java.lang.Long">
            <column name="DOCUMENT_SIZE" precision="10" scale="0" />
        </property>
        <property name="transformTechError" type="clob">
            <column name="TRANSFORM_TECH_ERROR" />
        </property>
        <property name="transformFuncError" type="clob">
            <column name="TRANSFORM_FUNC_ERROR" />
        </property>
    </class>
</hibernate-mapping>



But running the following ant-task:

Code:
<hibernatetool destdir="${DIR.SRC}">
    <jdbcconfiguration configurationfile="${DIR.CNF}/hibernate.cfg.xml"
                       revengfile="${DIR.CNF}/hibernate.reveng.xml" />
    <hbm2hbmxml/>
    <hbm2java jdk5="true" />
</hibernatetool>


gives a warning message in the Ant console:

Code:
[hibernatetool] WARNING: The JDBC driver didn't report any primary key columns in TDOCUMENT_FSI. Asking rev.eng. strategy



and produces this Document.hbm.xml:

Code:
<!-- Generated Aug 29, 2006 4:17:14 PM by Hibernate Tools 3.2.0.beta7 -->
<hibernate-mapping>
    <class name="com.sgcib.fsi.fsio.hib.Document" table="TDOCUMENT_FSI">
        <composite-id name="id" class="com.sgcib.fsi.fsio.hib.DocumentId">
            <key-property name="eventId" type="java.lang.Long">
                <column name="ID_EVENT" precision="10" scale="0" />
            </key-property>
            <key-property name="docCode" type="string">
                <column name="DOCUMENT_CODE" length="64" />
            </key-property>
            <key-property name="docType" type="java.lang.Long">
                <column name="ID_DOCUMENT_TYPE" precision="10" scale="0" />
            </key-property>
        </composite-id>
        <many-to-one name="event" class="com.sgcib.fsi.fsio.hib.TransformationEvent" update="false" insert="false" fetch="select">
            <column name="ID_EVENT" precision="10" scale="0" />
        </many-to-one>
        <many-to-one name="docType" class="com.sgcib.fsi.fsio.hib.DocumentType" update="false" insert="false" fetch="select">
            <column name="ID_DOCUMENT_TYPE" precision="10" scale="0" />
        </many-to-one>
        <many-to-one name="application" class="com.sgcib.fsi.fsio.hib.Application" fetch="select">
            <column name="ID_APPLICATION" precision="10" scale="0" />
        </many-to-one>
        <property name="status" type="string">
            <column name="STATUS" length="50" />
        </property>
        <property name="document" type="blob">
            <column name="DOCUMENT" not-null="true" />
        </property>
        <property name="transformStatus" type="string">
            <column name="TRANSFORM_STATUS" length="2" not-null="true" />
        </property>
        <property name="documentSize" type="java.lang.Long">
            <column name="DOCUMENT_SIZE" precision="10" scale="0" />
        </property>
        <property name="transformTechError" type="clob">
            <column name="TRANSFORM_TECH_ERROR" />
        </property>
        <property name="transformFuncError" type="clob">
            <column name="TRANSFORM_FUNC_ERROR" />
        </property>
    </class>
</hibernate-mapping>



This second Document.hbm.xml doesn't recognize the composite ID in the same way and doesn't produce the expected code.

Anything that I can do for this?

thanks in advance

_________________
-furner


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 12:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you probably unselected the "prefer basic composite ids" in the eclipse ui.

something i regretted exposing there since its bad to do so (in the sense the mappings are not what i would call Good ;)

i don't think i ever exposed that option in ant.

why do you want key-many-to-one ? It is definitly not recommended.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 12:26 pm 
Newbie

Joined: Fri Mar 24, 2006 11:46 am
Posts: 3
That's a "positive" on the unchecked "Generate basic-typed composite IDs".

Now that you mention it, I suppose that I can live without it, although I'll have to change the using code.

I'm using "<many-to-one>" to force the name of the attribute in the generated classes. Could you explain why this isn't recommended?

thanks

_________________
-furner


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 29, 2006 1:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Quote:
I'm using "<many-to-one>" to force the name of the attribute in the generated classes. Could you explain why this isn't recommended?


that is not what i didn't recommend. many-to-one is fine; it is key-many-to-one that is discouraged.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:05 am 
Newbie

Joined: Fri Mar 24, 2006 11:46 am
Posts: 3
<key-many-to-one> was generated by the plug-in because, as you mentioned, I had unchecked the "Generate Basic Typed Ids" box. I will have to change the usage code but I don't think this will be a problem. Thanks for the quick answer.

BTW: Why am I getting the warning message from the reverse?

Code:
WARNING: The JDBC driver didn't report any primary key columns in TDEPENDENT_TRANSFORMATION_FSI. Asking rev.eng. strategy


Do I need to rename the unique composite index or declare it in some other way?

thanks again

-alan

_________________
-furner


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 4:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
a unique index != primary key.

to create a primary key you use the PRIMARY KEY constraint.

e.g.
CREATE TABLE table_name
(column1 datatype null/not null,
column2 datatype null/not null,
...
CONSTRAINT constraint_name PRIMARY KEY (column1, column2, . column_n)
);

_________________
Max
Don't forget to rate


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

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.