-->
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.  [ 8 posts ] 
Author Message
 Post subject: Lightweight class and hbm2java generator
PostPosted: Thu May 12, 2005 7:54 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
Hibernate version: 3.0.3; respectively Hibernate tools as per CVS

Mapping example:
Code:
<hibernate-mapping package="com.ez.ezrt.model">
   <class name="ITDatabaseNL"
         table="ITDATABASE"
         mutable="false"
         batch-size="10">
         <id name="id"
         type="java.lang.Long"
         column="ID"
         unsaved-value="0">
      
         <generator class="identity" />
      </id>

      <property name="itName"
              type="java.lang.String"
              column="itName"
              not-null="true"
              unique="true"
              length="100" />
   </class>
   
   <class name="ITDatabase"
         table="ITDATABASE"
         mutable="false"
         batch-size="10"
         polymorphism="explicit">
      <meta attribute="extends">ITDatabaseNL</meta>
      
      <id name="id"
         type="java.lang.Long"
         column="ID"
         unsaved-value="0">
         <generator class="identity" />
      </id>

      <property name="itName"
              type="java.lang.String"
              column="itName"
              not-null="true"
              unique="true"
              length="100" />
             
      <property name="connectionURL"
              type="java.lang.String"
              column="connectionURL"
              not-null="true"
              length="100" />
   </class>
</hibernate-mapping>

According to LightweightClass the recommended solution is to use
Code:
polymorphism=explicit
.

I have find the way to specify that ITDatabase extends ITDatabaseNL in the generated code (see the
Code:
<meta>
usage).

However at the 2nd step i wanted to define that the generated fields in the ITDatabaseNL are protected level and so they are not getting regenerated in the ITDatabasa.

Is this possible?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 8:02 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
I have found the way to generate the field as protected
Code:
<meta attribute="scope-field">protected</meta>

but it seems the tool is not considering this when generating the extends class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 8:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what do you mean ?

it will generate protected fields for all the fields listed at the same level and under it in the xml.


/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 9:30 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
In the above case I expect (in fact, to reformulate :-) it would be nice) to have:
[code]
public class com.ez.ezrt.model.ITDatabaseNL {
protected Long id;
[....]

public Long getId() {...}

public void setId() {...}
}

public class com.ez.ezrt.model.ITDatabase extends ITDatabaseNL {
// surprize: in here just the property that is not already defined in the super
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 10:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hbx-259

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 10:16 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
This HBX-259 is for the other thread ;-).


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 10:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well cant hit the right posting each time ,)

...any way....

the meta attribute is just inserted literally - we don't try to be clever and merge stuff (it would be a pain to do correctly)

for that you would need to map it explicitly via inheritance.


...we *might* be able to support it in the future - but as far as i remember there are many common cases which is hard to do reliably.

add a jira for it.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 12, 2005 11:45 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
I agree with you (on both ideas ;-).

Can you point me to the right direction for using inheritance and the leightweight classes? (it seems i cannot figure out - is it the case of Table per class hierarchy scenario, without using a discrimitator column and respectively a discriminator-value in subclass definition?)


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