-->
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.  [ 5 posts ] 
Author Message
 Post subject: Middlegen: "long" or "Long" for id's?
PostPosted: Thu Feb 12, 2004 6:17 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
When I have a table with a PK of type INT8 with only one column, in the resulting VO generated with Middlegen we get a "Long". This is case of B (PK: y).

But when I have a table with a PK with two INT8 columns (composite) and one of them points to an other table, the one that doesn't point to anywhere is type "long" in the generated VO. I'm referring to "x" in the example.

Example:

Code:
A (PK: x, y)
          |
          |
          |----> B (PK: y)


Can someone please tell me why this behavior?
What makes exactly Middlegen choose from "long" or "Long" for the id types?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 10:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Middlegen has several layers for determining the type thus this can be hard to say what might be the factor.
What version of Middlegen / hibernate plugin are you using?
Can you show a snipit of the hbm and the table ddl?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 10:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
BTW: hbm mapping id as 'long' can be equal to java.lang.Long so both are valid for mapping to a java.lang.Long type in the POJO. Middlegen does not know about the HIbernate types unless you write your own HibernateJavaTypeMapper so you have further control over the initial types generated.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 13, 2004 5:48 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
david wrote:
Middlegen has several layers for determining the type thus this can be hard to say what might be the factor.
What version of Middlegen / hibernate plugin are you using?
Can you show a snipit of the hbm and the table ddl?


Thanks for the reply David.
I'm using Middlegen R3 for generation.


Here's an example mapping file
---------------------------------------

VersaoDocumento
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="vo.VersaoDocumento"
    table="versao_documento"
>

    <composite-id name="comp_id" class="vo.VersaoDocumentoPK">
        <key-property
            name="id"
            column="id"
            type="long"
            length="8"
        />
        <!-- bi-directional many-to-one association to Documento -->
        <key-many-to-one
           name="documento"
           class="vo.Documento"
       >
           <column name="documento_fk" />
       </key-many-to-one>
    </composite-id>   

    <property
        name="descricao"
        type="java.lang.String"
        column="descricao"
        length="-1"
    />
    <property
        name="userSubmissao"
        type="java.lang.String"
        column="user_submissao"
        length="10"
    />
    <property
        name="dataSubmissao"
        type="java.sql.Timestamp"
        column="data_submissao"
        length="8"
    />
    <property
        name="aprovado"
        type="boolean"
        column="aprovado"
        length="1"
    />
    <property
        name="userAprovacao"
        type="java.lang.String"
        column="user_aprovacao"
        length="10"
    />
    <property
        name="dataAprovacao"
        type="java.sql.Date"
        column="data_aprovacao"
        length="4"
    />
    <property
        name="userId"
        type="java.lang.String"
        column="user_id"
        not-null="true"
        length="10"
    />
    <property
        name="dtHr"
        type="java.sql.Timestamp"
        column="dt_hr"
        not-null="true"
        length="8"
    />

    <!-- associations -->

</class>
</hibernate-mapping>


DDL script
-----------------

Code:
CREATE TABLE VERSAO_DOCUMENTO (
       id INT8 NOT NULL
     , documento_fk INT8 NOT NULL
     , descricao TEXT
     , user_submissao CHAR(10)
     , data_submissao TIMESTAMP(10)
     , aprovado BOOLEAN
     , user_aprovacao CHAR(10)
     , data_aprovacao DATE
     , user_id CHAR(10) NOT NULL
     , dt_hr TIMESTAMP(10) NOT NULL
     , PRIMARY KEY (id, documento_fk)
     , CONSTRAINT versao_documento_doc_fk FOREIGN KEY (documento_fk)
                  REFERENCES DOCUMENTO (id)
);


The PK (id, documento_fk) has two INT8. But after generation, id will be of type long and the id of mapping Documento which is refrenced by documento_fk will be of type Long.

Just curious why the diference...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 14, 2004 12:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
What you showed is basically what I expected. I would have liked to see the mapping for the referenced table. In anycase, they ultimately become the same thing. You can use the GUI to change the type for the referenced table's primary key to also be 'long' (lowercase) so its consistent. This is the type I always use.

In R4 a custom type allocation mapper was introduced which addresses some of the (sometimes) odd type selections that Middlegen core allocates. For further information check the page on the wiki.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.