-->
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.  [ 13 posts ] 
Author Message
 Post subject: Middlegen without Ant - Possible?
PostPosted: Tue Mar 06, 2007 1:46 pm 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
We're dealing with a kind of unusual thing in our lab.

Implementing some comon Hibernate tools without using their natural Ant structure.

We're not reinventing the wheel. We even use Ant libraries. And get the same console messages. What we want is to replace the usual Ant document with a java program providing some integration and agility in the process.

Our goal is going from the database Schemas to the Hibernate Mapping Files (HBM) and then, from there to the POJOs.

So, instead of two separate steps, we have a program that accomplish both steps in a way as similar as possible in a single run.

Based on the HBM2Java technology a friend rebuilt the Ant aplication in a couple of Java Classes with good sucess.

Following his steps I've tried to do the same with the Middlegen plugin (more specifically focusing the transformation from Schemas to HBMs (Right now I can't remember if the Hibernate plugin for middlegen does anything else, pardon me).

The point where I'm stuck is:

If I instantiate a Task class during execution it will crash with a Nested Exception claiming that Middlegen must be on TaskDef in classpath or classpathref, not on system classpath when starting the Ant.

If I don't do it, the application will do nothing at all. Apparently the Ant won't even start. Adding a Taskdef to my project object makes no difference to this specific error case and I'm sure I need to manually set the Task to the Target (As this generates some ant starting messages in the console before the exception ocurs). This is something that I couldn't accomplish without creating the Task instance middlegen is crashing about.

I know this is not a very familiar scenario, but I have hopes of encountering someone else that tried a similar approach to an Ant structure.

Sorry for not being allowed to share my code with you, providing more specific data for you to analise my case.

Thanks in advance, for any contribution.

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 8:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
HIbernate does have a tool that allows you to generate XML from DDL. So Middlegen could be by-passed. See Tools documentation.

Having said that - It is true that Middlegen was designed to be launched using Ant as the primary trigger but it does not need to be. A good place to start is have a look at how MiddlegenIDE uses the Middlegen core to generate the artifacts.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 12:15 pm 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
I've read about Hibernate's own tool, but I also read that it is less efficient than Middlegen. Is that source wrong? I'll try to check the tool anyway.

I'll also look out for this new info about Middlegen. Thanks a lot.

EDIT:
"ReverseEngTool

A newcomer to the tool set. It provides a basic mapping from JDBC to one or more hbm.xml files. The mapping contains a class per table and lists the primary key and properties.
Shortcomings

(in no particular order)

* Only lists id, composite-id and properties.
* Does not "discover" foreign keys references.
* Requires definitions of foreign keys."

Is this the tool referenced by you? If so, please point me where can I find better documentation for it, because I don't seen to find. Also, is it updated since this particular stage?

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 07, 2007 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Hibernate tools are documented at http://www.hibernate.org/hib_docs/tools/reference/en/html/

There are benefits to both tools. Efficency?... I don't think thats a factor but then again I have spent much time looking at this.

Given you are looking for a cleaner programatic interface then Hibernate tools would be the choice. At the end of the day, either will do. Use what fits your needs and the way you work the best.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 08, 2007 10:30 am 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
I must admit "Efficient" was not the right term. What I meant is that I read that Ddl2Hbm was a deprecated tool and I've also stumbled across some guy's blog with comments on his experimentation swith booth Ddl2Hbm and Middlegen and coming to the conclusion the later was better though the earlier was easier to work with.

I've seen the Hibernate Tools documentation page before. Looking for info on this one deprecated tool I mentioned. Since you pointed it to me, I realized I should be missing something important there.

I saw the Eclipse plugins and their ability to generate the files I want, but it doesn't look much like I can adapt it to my needs.

Observing the Ant Tools chapter, I figured that you have a single tool (actually a single Ant) that is used for diverse objectives. So it can be used to do Hbm2Java, Java2Hbm conversions or generate configuration files and also to do Ddl2hbm conversions.

So... As far as I got it, I must combine <jdbcconfiguration>; <hbm2cfgxml>; <hbm2hbmxml> to achive the objective of creating Hbm files from Ddls. Is this right?

Once I understand this process I suppose I will be able to focus on transforming it to the form of the application I need.

Thanks for showing me the light and if I got it wrong, please do tell me.

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 09, 2007 3:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Yes you have the idea now. It is true that there have been alot of changes to the hibernate tools since H2 days. You should find it easy going from here.


BTW: You can programatically make this work as well.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 09, 2007 10:38 am 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
I'm trying to run the experimental ant and using hibernate.properties for configuration options.

(Below the reference I copied but changed to point to my stuff of course)

connection.username=test
connection.url=jdbc:mysql://127.0.0.1/test
dialect=net.sf.hibernate.dialect.MySQLDialect
connection.password=test
connection.driver_class=com.mysql.jdbc.Driver

I copied this style of hibernate properties from this page: http://www.hibernate.org/291.html#A9

Though mine has the lines in a diferent order.

Is this properties file right? Because somehow I can't make the ant task find it.

I point it's location within jdbc connection following this directive found on the documentation but it simply don't work. (I changed the "etc/" to point my ${src} directory witch is ".")

<jdbcconfiguration propertyfile="etc/hibernate.properties" />

What am I missing?

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 6:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You using HIbernate 3? (I know you are).

Your dialect reference is for version 2. Should be org.hibernate.dialect.MySQLDialect

The properties are all documented in the online manual so I suggest you review them using this resource.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 12, 2007 12:20 pm 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
Yes, I'm using Hibernate 3. (How good you knew).

Actually... I failed pointing out to you the properties properly. I posted here the reference I used, not my properties file.

I'm using org.hibernate.dialect.OracleDialect

I actually used other stuff we built here in the lab. as reference since I am going to access the same bases.

I'm gonna take a look around the online manual for these properties references, but I still don't understand why the ant can't find the properties file at all. And it states it explicity much before the exception occurs. It is the exception that claims no dialect has been specified, though the fact is the properties is not being found.

EDIT: Update:

Now that I realized that there is more on the online manual about the tools, I managed to fix the problems in the properties file. It still doesn't "find it" (and it states that in the console. But it seens to be working now.

My brand new problem is that after going all the way messing with strange tables I've never seen in my database user (I think they're some sort of info about my database that oracle keeps) it crashes claiming that two diferent classes have the same name...

Since I'll need the reveng.xml file to control the thing more properly anyway, I want to test it within the program to see if I won't get the same error again.

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 12, 2007 8:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
With Oracle set the schema you are using for the tables of interest.
Also, as you know, using the reveng to help fine tune the process.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 13, 2007 1:08 pm 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
After some studing and adjusting I reached a strange point.

EDIT: I managed to solve some of these, but decided to leave the references here. (----Problem #: description of actual status).

-----Problem 1: Solved after I added Tidy.jar to the classpath of the Ant

I run the Ant application. If I just point out the desired schema in the reveng file, nothing happens. If I point each one of the tables from my schema, individualy, then it finds them.

----------------------------------------------------------------------------------
-----Problem 2: I still have this one, but it doesn't seen to be affecting anything, I've got to check the HBM files and POJOs for a posssible problem from this.

While running, it gives the following message for each table it processes:

Exception while trying to get indexinfo on GERALDO.<TableName>=Exception while getting index info for GERALDO.<TableName>

Where <TableName> is the name of the table being processed at the moment. GERALDO (my name) is the name of the schema.

---------------------------------------------------------------------------------
------Problem 3: Adding the Tidy.jar to the classpath of the Ant obviously solved it.

At the end of the process the following message is displayed:

BUILD FAILED: java.lang.NoClassDefFoundError: org/w3c/tidy/Tidy

I don't know what this class Tidy is about. I saw no reference to it anywhere in the documentation.

UPDATE: I found about JTidy on the net and read a little about it. I suppose it's used to format the HBM files. I'm gonna test it now.

---------------------------------------------------------------------------------
--------Problem 4: Still there. I belive some study of the reveng.xml options may fix it. Tidy.jar solved the problem of the mappings not appearing into the cfg.

At the end, all but one Table had their HBM files created. The hibernate.cfg.xml file was created but no table was mapped into it. The one table that is missing is a table that links a many-to-many relation between two other tables and it only has two collums, each a foreign key from one of the other two tables.

---------------------------------------------------------------------------------
--------Problem 5: Done. Well, not really, I used the <hbm2java> tag in my ant and it did it pretty well.

Now I must test the results to see if I can create the POJOs from them, using the program already created by my friend.

----------------------------------------------------------------------------------



One final note: I know we're talking about a specific problem here, but a fellow worker here is trying to capture and print into a file the SQL queries created by Hibernate on the run. Is there a specific way to achieve this? He tried something with Log4J with no sucess and claims he didn't find anything within the Hibernate documentation. I'm still to check the documentation for this personally, but if you can point it out, will help us a lot.

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 3:34 pm 
Beginner
Beginner

Joined: Thu Jun 29, 2006 8:41 am
Posts: 41
UPDATE!

Problem 4 is solved. Nothing like reading the manual. :P

About my fellow's problem: He started a new project and all of a sudden the log4J solution works. Now we must figure out why it's not working on the project he needs it working...

Thanks for all the support and patience, David. You were a great help.

Now I'm trying to do the thing programatically... let's all pray it works!

_________________
Falci - Heavy Worker!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 9:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Your welcome.


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