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.  [ 2 posts ] 
Author Message
 Post subject: Middlen output for tables with no PK
PostPosted: Tue Dec 30, 2003 4:50 pm 

Joined: Tue Nov 11, 2003 7:35 pm
Posts: 63
I have a table that has no primary key (this is a legacy table so it is not possible to change it now.) The middlegen plugin is correctly placing all of the columns as part of the composite pk. However, one of the columns happens to be a many-to-one association. But the plugin is generating the hbm xml for this column as if it were a regular association, e.g. it is generating a many-to-one instead of a key-many-to-one. Is this a bug?

Here is a listing of my generated xml:

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




    <!-- associations -->
    <!-- uni-directional one-to-one association to QwEnvrmtCd -->
        <column name="ENVRMT_CD" />


notice that the many-to-one association is not a key-many-to-one that is part of the composite key.

Beleive it or not this makes a difference for what I am trying to accomplish. Specifically I am creating a renderer for hbm2java to output DAO classes. I need some way to determine if a class has no pk, in which case certain methods would not be output. The only way I can think of to accomplish this is to check all the fields and running FieldProperty.isIdentifier() on them. If all the fields are an identifier then I assume the class has no PK. However since middlegen does not render the many-to-one as part of the key the isIdentifier() for the field returns false, incorrectly indicating that the table HAS a pk. If there is no way to render the association as a key-many-to-one, does anyone perhaps some other method to determine if a table has no pk?


 Post subject:
PostPosted: Sat Jan 03, 2004 11:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Middlegen support for non-primary key tables is minimal. It by default generates the compound key but it does not determine any foreign key associations. I have a problem with any table that does not have a PK so I did not want to spend to much time in this area. It can be done with a few mods to the velocity script.

BTW: You don't have to have the association as a key. The association just has to have the insert and update attributes set to false. This is the best (and easiest) solution approach for this problem (rather than filling up the template).

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