-->
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.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Explicit mapping of tablenames to classnames
PostPosted: Wed Jan 04, 2006 8:09 am 
Newbie

Joined: Mon Jan 02, 2006 3:22 pm
Posts: 4
Hi.

Do the Hibernate Tools support a project specific or let's say explicit mapping of database table names to class names?

By default, the tools are mapping my table named REPORTS (which is written in plural as it represents a set of data) to a Java class named Reports.java (which should be written as singular "Report.java").

The reveng file doesn't seem to offer such a support.

Does anybody know how to achieve this. But, please, don't give me advice to change the tablename!

Thanks in advance

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 6:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
http://www.hibernate.org/hib_docs/tools/ant/index.html plugin a custom naming strategy.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 8:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
as david says or

put
<table name="REPORTS" class="f.q.c.n.Report"/>

in the reveng.xml.

The latest release does not provide ui for this attribute, but the engine will use and work with it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Mapping Tables to classes
PostPosted: Thu Jan 05, 2006 7:54 am 
Newbie

Joined: Mon Jan 02, 2006 3:22 pm
Posts: 4
Hi,

thanks a lot. But the Tools for Eclipse IDE do not support this table-tag, yet. Is there some gui component for the eclipse tools in the works contributing to this?

Thanks a lot

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 8:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it does support this table tag - its managed via the "Tables & Columns" tab of the reveng.xml editor.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Not picking up the table tag
PostPosted: Wed Feb 01, 2006 11:34 am 
Newbie

Joined: Wed Dec 21, 2005 6:05 pm
Posts: 5
Location: Washington DC
I've been using tools to generate my hibernate files and java files. I wanted to change tools so the plural table name would generate a singular java class name (as in this example).

max wrote:
put
<table name="REPORTS" class="f.q.c.n.Report"/>

in the reveng.xml.

The latest release does not provide ui for this attribute, but the engine will use and work with it.


However the table tag never seems to get picked up.

I'm not using eclipse, I'm using an ant script. I know that my hibernate.revenge.xml is being used because the table-filter tag is working fine. Here's my file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
  <table-filter match-name="DASHBOARD_DISASTERS"/>
  <table-filter match-name="DASHBOARD_DISASTER_LOCATIONS"/>
 

  <table name="DASHBOARD_DISASTERS" class="gov.fema.asd.dashboard.model.DashboardDisaster"/>
  <table name="DASHBOARD_DISASTER_LOCATIONS" class="gov.fema.asd.dashboard.model.DashboardDisasterLocation"/>


</hibernate-reverse-engineering>


Any Idea why this wouldn't be working, or where else I should be looking?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you probably need to set default schema/catalog or use explicit names in the reveng.xml

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 3:56 pm 
Newbie

Joined: Fri Feb 10, 2006 1:39 pm
Posts: 3
I too am using the Ant script to reverse engineer a database, and am trying to map table names to classnames using the <table> tag in the reveng.xml file. Like ponticello, I know my <table-filter> tag is working, but cannot get the <table> tag to have any effect; the generated mappings and POJOs always contain the default classnames.

In the <table> tag, I have tried specifying just the name, and also tried specifying the name and schema. Neither attempt worked. There is no catalog name available to me, because my database (MySQL 5.0) by default uses a null catalog name. (I have not found a way to change the catalog name, even as root.) I have tried unqualified class names and fully qualified -- neither worked.

Any idea what the problem is? Do I need to find a way to set the catalog name? Below is the reveng.xml file I am using, and the ant target.


My environment

Windows XP
Hibernate 3.1
hibernate-tools-3.1.0.beta4
MySQL 5.0

My hibernate.reveng.xml file

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
  SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
    <table-filter match-name="dd_service"/>
    <table schema="data_driven"
           name="dd_service"
           class="com.tmobile.datadriven.DdServiceImpl"/>
</hibernate-reverse-engineering>


My ant target

Code:
   <target name="hibernate-mappings" description="Generate hibernate mappings from schema">
        <mkdir dir="target/mappings"/>
        <hibernatetool destdir="target/mappings">
            <classpath refid="hibernate-mappings-classpath"/>
            <jdbcconfiguration
                configurationfile="config/hibernate.cfg.xml"
                revengfile="config/hibernate.reveng.xml"
                packagename="com.tmobile.datadriven"
            >
            </jdbcconfiguration>
            <hbm2hbmxml/>
            <hbm2java/>
        </hibernatetool>
    </target>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
show me an example of a hbm.xml generated from this...esepcailly interested in what catalog/schema it puts in there

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:10 pm 
Newbie

Joined: Fri Feb 10, 2006 1:39 pm
Posts: 3
Hi Max,

Thank you for responding so promptly. Below is the DdService.hbm.xml generated by my example. It used the schema name as the catalog name.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 10, 2006 12:06:38 PM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping>
    <class name="com.tmobile.datadriven.DdService" table="dd_service" catalog="data_driven">
        <id name="id" type="short">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="name" type="string">
            <column name="name" length="24" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: more about <table> tag in reveng.xml
PostPosted: Fri Feb 10, 2006 7:20 pm 
Newbie

Joined: Fri Feb 10, 2006 1:39 pm
Posts: 3
Hi Max,

When the Ant task "hibernatetool" is configured with a jdbcconfiguration, it appears to ignore the "catalog" value within the <table> tag in a reveng.xml file. It appears always to use the schema name as the catalog name. When I use

Code:
<hibernate-reverse-engineering>
    <table-filter match-name="dd_service"/>
    <table catalog="current"
           schema="data_driven"
           name="dd_service"
           class="com.tmobile.datadriven.DdServiceImpl"/>
</hibernate-reverse-engineering>


the generated hbm.xml includes the line

Code:
   <class name="com.tmobile.datadriven.DdService" table="dd_service" catalog="data_driven">


I get the same hbm.xml file when I use catalog="junk", and also when I omit the catalog value completely. The result is that I am unable to customize classnames when reverse engineering from a schema.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 11, 2006 3:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the table is in the data_driven catalog.

either set default_catalog to data_driven or use set catalog on the <table> in reveng.xml

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 12:23 am 
Beginner
Beginner

Joined: Fri Jun 10, 2005 5:26 am
Posts: 25
Location: Adelaide, South Australia
Is there any chance the next release could include the ability (without having to go through all the hassle of implementing custom handlers) to have hbm2java just map table names directly to java classes. Similary functionality for relationships would be great too.

It's annoying to end up having a perfectly valid plural relationship called "propertieses" after the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 4:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
please explain me how you think such a strategy should look like ? And afterwards explain me the chance of this strategy being used by others without any change ? ...we can't deliver every conceivable naming strategy and the ones we deliver simply handles the most common ones we have observered + we give you the possibility to configure the heck out of it. btw. the upcoming allows you to define relationship names in the reveng.xml.

The plural thing is something we just need to improve by e.g. have a whitelist of words that should just pass through.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 28, 2006 5:57 pm 
Beginner
Beginner

Joined: Fri Jun 10, 2005 5:26 am
Posts: 25
Location: Adelaide, South Australia
Max, what I'm trying to get at here is a simple and convenient option that attempts absolutely no name massaging whatsoever. Preferably one that doesn't require the implementation of custom strategy.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next

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.