-->
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.  [ 11 posts ] 
Author Message
 Post subject: POJO generation from DB, foreign keys
PostPosted: Thu Mar 15, 2007 3:00 pm 
Newbie

Joined: Thu Mar 15, 2007 2:53 pm
Posts: 9
I am generating POJOs with ant script from DB.

I want to generate my foreign key references as scalar types.

For example:


User to UserStatus

I want to have my User POJO object to have

setUserStatusId(Long) instead of setUserStatus(UserStatus).

Looks like something like this is possible in eclipse with "Generate basic typed composite ids" field.

Does any one know how I can control this using ant build.xml or one of the properties files.

Thanks
Paddy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 3:50 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
You might be able to do that in the hibernate.reveng.xml file. Try
Code:
...
  <table name="USER">
    <foreign-key constraint-name="FK_USER_USERSTATUS" foreign-table="USER_STATUS">
      <many-to-one exclude="true"/>
      <set exclude="true"/>
    </foreign-key>
  </table>
...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 4:09 pm 
Newbie

Joined: Thu Mar 15, 2007 2:53 pm
Posts: 9
That doesn't do it. It stll generating a member variable UserStatus.

like

private UserStatus userStatusByUserStatusId;

along with getter and setters.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 8:17 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:20 am
Posts: 40
Location: Vienna
annanasi should be right, but the <set exclude="true"/> is not really necessary here as you have a n:1 relation.
But see the Hibernate Tools 3.2.0beta9 documentation for more details on this (esp. chapter 5.2.4.3 <foreign key>

Of course you have to make sure that your hibernate.reveng.xml file is used.
So in your ant script, you must have something like this (note the revengfile attribute):

Code:
<jdbcconfiguration configurationfile=".\hibernate-hbm2java.cfg.xml"
             packagename="${dir.gensrc.package}"
             revengfile="hibernate.reveng.xml"
             detectmanytomany="false"
             >


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 11:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
don't get why you would ever want this, but you could write a custom MetaDataDialect that returns zero foreignkeys for the tables you don't want references in the objectmodel.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 8:31 am 
Newbie

Joined: Thu Mar 15, 2007 2:53 pm
Posts: 9
Thanks Max. That helps.

I want our pojos to be simple value objects. I don't like them to be doing what's otherwise handled by DB and application transactional code such as referential integrigy, constraint management etc.,

Thanks again


Top
 Profile  
 
 Post subject: The same thing I need...
PostPosted: Thu Apr 05, 2007 5:16 am 
Newbie

Joined: Thu Mar 29, 2007 7:36 am
Posts: 9
Location: Romania
Hi preddy98!
Can You tell me how have You finally resolved?

I want to be generated just a simple POJO without foreign keys mapping. (Oracle)

I make the generation with Ant.
So my code looks like:
Code:
        <hibernatetool destdir="${project.src}">
            <jdbcconfiguration
                    configurationfile="${project.etc}\hibernate.cfg.xml"
                    revengfile="${project.etc}\hibernate.reveng.xml"
                    packagename="${package.name}"
                    reversestrategy="org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy"
                    detectmanytomany="false">
            </jdbcconfiguration>
            <hbm2java jdk5="${hibernate.jdk5}" ejb3="false"/>
        </hibernatetool>


..and the taskdef:
Code:
    <taskdef name="hibernatetool"
             classname="org.hibernate.tool.ant.HibernateToolTask"
             classpathref="toolslib"/>


But it seems to not work.
So I still have in pojo the Set-s at foreign keys.

Or have You writted your own class which implements MetaDataDialect?
Or this can made by changing the reverse engineering strategy?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 07, 2007 3:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you need to customize the metadialect to lie by not returning in foreignkey info.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: using MetaDataDialect
PostPosted: Tue Apr 10, 2007 5:33 am 
Newbie

Joined: Thu Mar 29, 2007 7:36 am
Posts: 9
Location: Romania
I can implement the MetaDataDialect in a class(MyMetaDataDialect), but where must I use that class?
How can I set to hibernatetool, or jdbconfiguration to use that class?
As I writted a little bit upper, there are two customizable classes which are now used, the reversestrategy as org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy
and maybe in the hibernate.cfg.xml the
<property name="dialect">org.hibernate.dialect.OracleDialect</property>.

Or exists a property which takes a customized MetaDataDialect?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 10, 2007 5:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://www.hibernate.org/hib_docs/tools ... e/#d0e1781

hibernatetool.metadatadialect

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Tue Apr 10, 2007 10:16 am 
Newbie

Joined: Thu Mar 29, 2007 7:36 am
Posts: 9
Location: Romania
Thank You Max!

(I have searched/read parts from http://www.hibernate.org/hib_docs/tools ... tml_single but it seems I have missed).


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