-->
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: Hibernator closes session too soon
PostPosted: Tue Feb 03, 2004 7:47 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 12:44 pm
Posts: 40
I have been trying out the Hibernator plugin 0.9.6 in Eclipse 3m3 and to the most part have been successful. I used middlegen to generate the java and mapping files, tweaked the latter to change primitive types to java types and successfully ran some queries.

However, some of the table mappings are complicated...

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 the Middlegen Hibernate plugin

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

<class
    name="com.landg.clex.hibernate.Tia00570"
    table="TIA00570"
    schema="CLEX"
>

    <id
        name="claimCaseNumber"
        type="java.lang.Integer"
        column="CLAIM_CASE_NUMBER"
    >
        <generator class="assigned" />
    </id>

    <property
        name="claimType"
        type="java.lang.String"
        column="CLAIM_TYPE"
        not-null="true"
        length="2"
    />
    <property
        name="claimCaseStType"
        type="java.lang.String"
        column="CLAIM_CASE_ST_TYPE"
        not-null="true"
        length="2"
    />
    <property
        name="manualInputInd"
        type="java.lang.String"
        column="MANUAL_INPUT_IND"
        not-null="true"
        length="1"
    />
    <property
        name="createTimestamp"
        type="java.sql.Timestamp"
        column="CREATE_TIMESTAMP"
        not-null="true"
        length="26"
    />
    <property
        name="salary"
        type="java.math.BigDecimal"
        column="SALARY"
        length="15"
    />
    <property
        name="occupationType"
        type="java.lang.String"
        column="OCCUPATION_TYPE"
        length="2"
    />
    <property
        name="persId"
        type="java.lang.String"
        column="PERS_ID"
        length="9"
    />
    <property
        name="logonId"
        type="java.lang.String"
        column="LOGON_ID"
        length="7"
    />
    <property
        name="othContractInd"
        type="java.lang.String"
        column="OTH_CONTRACT_IND"
        length="1"
    />
    <property
        name="othMatCntrInd"
        type="java.lang.String"
        column="OTH_MAT_CNTR_IND"
        length="1"
    />
    <property
        name="clmPackDespdInd"
        type="java.lang.String"
        column="CLM_PACK_DESPD_IND"
        not-null="true"
        length="1"
    />
    <property
        name="maintUserId"
        type="java.lang.String"
        column="MAINT_USER_ID"
        not-null="true"
        length="7"
    />

    <!-- associations -->
    <!-- bi-directional one-to-many association to Tia00602 -->
    <set
        name="tia00602s"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="CLAIM_CASE_NUMBER" />
        </key>
        <one-to-many
            class="com.landg.clex.hibernate.Tia00602"
        />
    </set>
    <!-- bi-directional one-to-many association to Tia00590 -->
    <set
        name="tia00590s"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="CLAIM_CASE_NUMBER" />
        </key>
        <one-to-many
            class="com.landg.clex.hibernate.Tia00590"
        />
    </set>
    <!-- bi-directional one-to-many association to Tia00591 -->
    <set
        name="tia00591s"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="CLAIM_CASE_NUMBER" />
        </key>
        <one-to-many
            class="com.landg.clex.hibernate.Tia00591"
        />
    </set>
    <!-- bi-directional one-to-many association to Tia00584 -->
    <set
        name="tia00584s"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="CLAIM_CASE_NUMBER" />
        </key>
        <one-to-many
            class="com.landg.clex.hibernate.Tia00584"
        />
    </set>
    <!-- bi-directional one-to-many association to Tia00571 -->
    <set
        name="tia00571s"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="CLAIM_CASE_NUMBER" />
        </key>
        <one-to-many
            class="com.landg.clex.hibernate.Tia00571"
        />
    </set>
    <!-- bi-directional one-to-many association to Tia00597 -->
    <set
        name="tia00597s"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="CLAIM_CASE_NUMBER" />
        </key>
        <one-to-many
            class="com.landg.clex.hibernate.Tia00597"
        />
    </set>
    <!-- bi-directional one-to-many association to Tia00586 -->
    <set
        name="tia00586s"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="CLAIM_CASE_NUMBER" />
        </key>
        <one-to-many
            class="com.landg.clex.hibernate.Tia00586"
        />
    </set>

</class>
</hibernate-mapping>


...leading to the following exception...
Code:
    "Failed to lazily initialize a collection - no Session"


Reading some of the postings on the Hibernate forum suggests that this is due to the session being closed prematurely when lazy loaded collections are being used, so the subsequent load doesn't have a session to use.

Is this a problem with Hibernator?

Also, is there any plans to update the plugin to use Hibernate 2.1.1 in the near future?

Best regards,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 3:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The error is reported, at you have said, when you wanted to get the collection which is lasy and the session is close. I would consider generating a report for the hibernator plugin (which I have not tried but should).

To answer your other question, Middlegen is being updated with further features and many of them includes better support for the 2.1 feature set.
I have the feature set I am targeting (with a few like it to haves) so the next release could be a big one. Is there something you have in mind?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 3:19 pm 
Beginner
Beginner

Joined: Mon Nov 24, 2003 12:44 pm
Posts: 40
No specific requests for features. However, it would be nice if Middlegen could handle Primary Key types of CHAR FOR BIT DATA a bit different. The last time I reverse engineered my schema, it generated the types as byte[], which weren't handled by hibernate. I had to create a specific type as described in the WIKI to handle this situation. Maybe this is actually an enhancement to Hibernate itself. I also had to change all the primative types to objects to stop errors with CGLIB.

A couple of minor points about the Middlegen GUI...
When the gui opens up, the division bar is right at the top of the screen. The first few times I used it, I didn't realise it had generated a schema diagram. I assumed it was broken until the other day, when I pulled the bar down and found the diagram. ;-)

A feature you could provide is an ability to zoom the diagram and multi select the objects so they can be moved around en mass. My schema was huge with 200+ tables. Took a lot of manipulating to get it looking nice.

Apart from those things all is ok and I appreciate the effort gone into writing and maintaining the tool.

Best regards
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 9:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Thanks for the feedback.
Not sure why the GUI did not open with the splitter in the middle. Maybe a GIF image with the instructions will help enlighten them with what to expect.
The latest version R4 has the ability for you to introduce your own type mapper - I have provided one that address the primitive type issue. You could create your own type mapper plugin for the plugin to deal with other issues you may have in this area.
The GUI does need a few more feature to deal with large table structures. I am looking into it and hope to make steady progress in this area.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 5:52 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 12:44 pm
Posts: 40
Thanks David,

I 've just spotted the HibernateJavaTypeMapper in the notes and have added it to my script...
Code:
     <!-- Plugins -->
     <hibernate
        destination="${build.gen-src.dir}"
        package="${name}.hibernate"
        javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
     />

...and am now regenerating my schema.

Cheers
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 10:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Great.

Just a note for those that are now using (the recommended) supplied JavaTypeMapper. It applies when you don't have a mapping already selelcted. In otherwords you may need to remove the preferences file (which contains the state) or edit it slightly for the services of the TypeMapper plugin to be used.


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.