-->
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.  [ 12 posts ] 
Author Message
 Post subject: [Hibernate Tools] remove one-to-many relations
PostPosted: Fri Aug 04, 2006 4:43 am 
Newbie

Joined: Wed Jul 19, 2006 4:05 am
Posts: 13
Hi,

Hibernate version: 3.1.3

JBoss IDE version: 2.0.0Alpha

I use the Hibernate Code Generation with a reveng.xml and a reveng. strategy files.

Hibernate Tools generates the many-to-one relations well. But, I would like to prevent the generation of the (reverse) one-to-many relations. How can I do this please ?

Thx,


Top
 Profile  
 
 Post subject: Re: [Hibernate Tools] remove one-to-many relations
PostPosted: Fri Aug 04, 2006 4:46 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi,
Lets say that you have two tables, APP_USER and APP_USER_ROLE where a AppUser object can have a Set of AppUserRole (this is the correct mapping) and Hibernate tools will generate a AppUser as a private member in ApPUserRole. This is the relationship that you whant to delete. Right?

the solution is to put some xml in your reveng.xml file.

Code:
   <table schema="MYSCHEMA" name="APP_USER_ROLE">
      <foreign-key constraint-name="FK_APP_USER_APP_USER_ROLE">
         <many-to-one property="AppUser" exclude="true" />
      </foreign-key>
   </table>


where constraint-name is the name for the foreign key relationship between the two tables. Many-to-one property is the name of the property that Hibernate creates in your AppUserRole. In this case AppUser.

Table schema and name I do not need to explain....

Cheers,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 05, 2006 2:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
fastest way is to implement a custom reverese engineering class and return false for excludeForeignKeyAsCollection then no one-to-many will be created.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: [Hibernate Tools] remove one-to-many relations
PostPosted: Mon Aug 07, 2006 7:25 am 
Newbie

Joined: Wed Jul 19, 2006 4:05 am
Posts: 13
Jake123 wrote:
the solution is to put some xml in your reveng.xml file.

Code:
   <table schema="MYSCHEMA" name="APP_USER_ROLE">
      <foreign-key constraint-name="FK_APP_USER_APP_USER_ROLE">
         <many-to-one property="AppUser" exclude="true" />
      </foreign-key>
   </table>



The right solution is in the reveng.xml file. But the exact syntax is :
Code:
   <table schema="MYSCHEMA" name="APP_USER_ROLE">
      <foreign-key constraint-name="FK_APP_USER_APP_USER_ROLE">
         <set property="AppUser" exclude="true" />
      </foreign-key>
   </table>


Thanks a lot for your help. My problem is solved !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 7:29 am 
Newbie

Joined: Wed Jul 19, 2006 4:05 am
Posts: 13
max wrote:
fastest way is to implement a custom reverese engineering class and return false for excludeForeignKeyAsCollection then no one-to-many will be created.

I thought to use the DelegatingReverseEngineeringStrategy.excludeForeignKeyCollection() method. Because is it the fastest way.
But this method is never called in my custom reverse engineering strategy. :-/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 8:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
show me your code for the custom strategy and how you set it up.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 10:35 am 
Newbie

Joined: Wed Jul 19, 2006 4:05 am
Posts: 13
Sorry Max,

I've just realised that I wrote a (beginner) error :
Code:
   public boolean excludeForeignKeyCollection(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
      return true;
   }


The right code is :
Code:
   public boolean excludeForeignKeyAsCollection(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
      return true;
   }


I implemented the excludeForeignKeyCollection() methode instead of excludeForeignKeyAsCollection(). Whereas I did a call to the good super.excludeForeignKeyAsCollection() method !

Thanks again to Max and Jacob !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 10:37 am 
Newbie

Joined: Wed Jul 19, 2006 4:05 am
Posts: 13
I cannot give two rates when users give me two solutions ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 10:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you can only rate a certain number of times in one thread....can't remember how many though.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 10:51 am 
Newbie

Joined: Wed Jul 19, 2006 4:05 am
Posts: 13
I rated the Jacod reply. But now, I cannot rate your reply. :-(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I'll survive :)

(but you should be able to rate 3 times per thread)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: [Hibernate Tools] remove one-to-many relations
PostPosted: Fri Dec 04, 2009 4:53 am 
Newbie

Joined: Fri Dec 04, 2009 4:34 am
Posts: 1
Hi,

I have a similar situation, I want to exclude some of the inverse sets from my mapping files, like the one below:
Code:
        <set name="rumWayLineMultiples" inverse="true">
            <key>
                <column name="ID_HIERACHY_LISTE" precision="22" scale="0" not-null="true" />
            </key>
            <one-to-many class="com.test.model.RumWayLineMultiple" />
        </set>

So in my RevengStrategy.java I've overridden the excludeForeignKeyAsCollection() method like this :
Code:
   public boolean excludeForeignKeyAsCollection(String FK, TableIdentifier tableIdentifier, List list, TableIdentifier tableIdentifier1, List list1) {
   boolean collectionInverse = isForeignKeyCollectionInverse(FK, tableIdentifier, list, tableIdentifier1, list1);
        if(collectionInverse) {
            return true;
        }
        return false;
    }

But this doesn't work quite the way I expected. It removes all the <sets> but it also removes some <many-to-one> mappings.
There is another method excludeForeignKeyAsManytoOne() and I thought that this handles <many-to-one>.

Any ideas why it does that ? And is it possible to exclude only certain <sets> ? I mean if a mapping file has 3 <sets>, can I tell excludeForeignKeyAsCollection() based on the foreign key or tables identifiers exactly which <sets> I want excluded ?

Thanks


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