-->
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.  [ 7 posts ] 
Author Message
 Post subject: CodeGeneration imports superclass attributes
PostPosted: Thu Jan 15, 2004 6:46 pm 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
Hello,

I've a question about the CodeGenerator - I love it, I think it's great, the Finder generator is really cool - but....

I have a mapping file that declares a base superclass with a primary key and a single attribute - ObjectType - which is a <many-to-one> to an ObjectType Table. All other classes/tables are joined-subclasses. The problem is that this ObjectType is getting imported in all classes in this package - thereby causing compilation to fail. Is there any way I can prevent this from happening? I've considered changing the access attribute of the <many-to-one> for ObjectType to private, but I don't really like that solution (if it is in fact one). Here's a piece of the mapping file:

Code:
<hibernate-mapping package="org.wgbh.scape.domain" auto-import="false">
   
   <class name="org.wgbh.scape.domain.UnidentifiedFoundationObject"  optimistic-lock="dirty" polymorphism="explicit" table="OBJECT">
      <meta attribute="class-description">
         The UnidentifiedFoundationObject class is the base-class for all
         objects within Scape. It is an abstract class.
         @author Brian R. Wainwright
         @version 1.0
      </meta>
      <meta attribute="scope-class" inherit="false">public abstract</meta>
      <meta attribute="implements">org.wgbh.scape.Associable</meta>
      <id column="OBJECT_ID" name="objectIID" type="string" unsaved-value="id_value">
         <generator class="uuid.hex"/>
      </id>
      <property column="ACCESS_PRIVILEGE" insert="true" name="accessPrivilege"
         type="string" update="true"/>
            
      <many-to-one class="ObjectType" column="OBJECT_TYPE_ID" insert="true"
         name="objectType" update="true">
         <meta attribute="finder">findByObjectType</meta>
      </many-to-one>

<joined-subclass name="org.wgbh.scape.domain.AccessGroup" table="ACCESS_GROUP">
         <meta attribute="class-description">
         
         @author Brian R. Wainwright
         @version 1.0
         </meta>
         <key column="ACCESS_GROUP_ID"/>
         <set name="objects" table="OBJECT_ACCESS_GROUP" lazy="true" outer-join="auto" batch-size="50" inverse="true">
            <key column="ACCESS_GROUP_ID"/>
            <many-to-many class="UnidentifiedFoundationObject" column="OBJECT_ID"/>
         </set>
         <property column="ACCESS_LEVEL" name="accessLevel" type="integer"/>
            
         <property column="ACCESS_LEVEL_NAME" name="name" type="string">
            <meta attribute="finder">findByAccessLevel</meta>
         </property>
      </joined-subclass>

</class>
   
</hibernate-mapping>



and some resulting code generated by the CodeGenerator:

Code:
package org.wgbh.scape.domain;

import ObjectType; //this line causes compilation to fail
import java.io.Serializable;
import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
*          
*          @author Brian R. Wainwright
*          @version 1.0
*          
*/
public class AccessGroup extends UnidentifiedFoundationObject implements org.wgbh.scape.Associable,Serializable {

    /** nullable persistent field */
    private int accessLevel;

    /** nullable persistent field */
    private String name;

    /** persistent field */
    private Set objects;

    /** full constructor */
    public AccessGroup(String accessPrivilege, ObjectType objectType, Set associatedObjects, Set associatedProjects, Set associations, Set comments, Set attributes, Set access, int accessLevel, String name, Set objects) {
        super(accessPrivilege, objectType, associatedObjects, associatedProjects, associations, comments, attributes, access);
        this.accessLevel = accessLevel;
        this.name = name;
        this.objects = objects;
    }





Any help is appreciated. Thanks!

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


Top
 Profile  
 
 Post subject: Reason why this is happening?
PostPosted: Thu Jan 15, 2004 6:48 pm 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
Is it because I have the base class decalred as abstract? This would make sense i suppose....

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


Top
 Profile  
 
 Post subject: Re: Reason why this is happening?
PostPosted: Fri Jan 16, 2004 1:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
brian_wainwright wrote:
Is it because I have the base class decalred as abstract? This would make sense i suppose....


you are using only the class name - use the fully qualified name as required normally...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 10:55 am 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
Thanks for the reply Max. I'm actually not really concerned about the compilation issues - I guess I wasn't clear. The real issue is the behavior of the CodeGenerator for joined-subclasses. ObjectType represents a relationship to another sub-class/table (many-to-one in this case). Unlike accessPrivilege, which is a simple String property, the ObjectType class is being imported into all subclasses (concrete and otherwise) of UnidentifiedFoundationObject. Because all these classes are in the same package, this isn't necessary. You're correct that using the fully qualified class name in the import statement compiles the class. so I guess my question is two-fold:

1. Can I turn off this behavior in CodeGenerator through the mapping file? I imagine that CodeGenerator doesn't recognize that all these classes are in the same package (there are over 100) and doesn't really care about what package they are in other than to generate the package declaration.

2. If I can't turn it off, how can I get the fully qualified name to appear in the import statement - auto-import = "false" only applies to HQL.

Thanks for your advice!

--BW

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 11:04 am 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
Hi again Max,

I think I misunderstood YOU. I believe you reference the fully qualified class name in the mapping file - in the <many-to-one> declaration. Sorry. My other question still remains however, how does CodeGenerator view classes in the same package - if at all?

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2004 5:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
The problem you are seeing is because you use the newly added package="x.y.z" keyword which is not yet supported by the hbm2java....sorry.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2004 9:58 am 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
That's cool! Thanks for the response.

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


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