-->
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.  [ 9 posts ] 
Author Message
 Post subject: Using middlegen-hibernate without ant
PostPosted: Mon Sep 20, 2004 7:49 am 
Newbie

Joined: Mon Aug 23, 2004 9:23 am
Posts: 12
Hibernate version: 2.0


Hello again, another question.
I would like to use middlegen and hibernate without using ant (although I should use ant jars for sure), so I want to use the proper classes (middlegen.MiddlegenTask and net.sf.hibernate.tool.hbm2java.Hbm2JavaTask) inside my code. I have got both Middlegen and Hibernate APIs and what I want to know is which are the functions or methods that I MUST use.

--middlegen.MiddlegenTask:
With Middlegen I suppose execute() is the final step but previously I should set all properties calling setAppname(), setDatabaseURL, setGUI(), etc.
But, how can I "add" or "set" the hibernate plugin?? (the only one I want to use)
Perhaps using createDynamicElement()? And how?

--net.sf.hibernate.tool.hbm2java.Hbm2JavaTask
With Hibernate, execute() should be the final step too, Doesn't it?
Before it, I should call setConfig(), addFileset() and setOutput().
But there are two methods that I don't know If I should use:
setClasspath() and processFile().
Are they useful?

Any other important step?

Thanks and kind regards again,
Jose Luis


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 20, 2004 7:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
It would be easier for you to use Ant to drive the settings and the base configuration data structures. I have not tried it but I would be looking at calling Ant programatically rather then simulating what Ant does then starting Middlegen.

What is your reason for doing this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 21, 2004 2:52 am 
Newbie

Joined: Mon Aug 23, 2004 9:23 am
Posts: 12
Hello,
I think that ant is a very powerful tool but in my opinion, development is the environment where it should be used. I would like to use middlegen and hbm2java in my code and link it to a larger application. All executable files contains "java ..." and using ant wouldn't be very clear. Besides, someone who wanted to use my app, should install Ant first and I would like to avoid this step.
I will try but if I find it very difficult, I will have to use Ant at the end.
I supposed that someone in your team wrote the middlegen and hbm2java tasks java code and maybe could help me.

Thanks and kind regards,
Jose Luis


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 21, 2004 6:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Yes we (Max did hbm2java task) did write the code. I was trying to understand the context. What tool/program are you writing? In anycase, you can ask question to the forum and we will see if we can help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 9:53 am 
Newbie

Joined: Mon Aug 23, 2004 9:23 am
Posts: 12
Hello,
Well, I am doing an application where I must execute an *.bat. I musn't use Ant although I can use its jars.
The *.bat contains a
java -classpath ...
command, that must do:

-Call the middlegen task, using only the hibernate plugin and a velocity template (with a fileproducer?) that allows me to avoid associations. This is the most difficult thing because calling a task in my code is easy but using the hibernate plugin and the template, mmm, I don't know what I should do yet.
The middlegen task generates the *.hbm.xml files I need.

-Call the hbm2java task that uses the *.hbm.xml fileset and generates the *.java. I have already done it. It was in short:
Code:
            ...
            Hbm2JavaTask task = new Hbm2JavaTask();
            FileSet fSet = new FileSet();
            fSet.setDir(srcDir);
            fSet.setCaseSensitive(false);
            FilenameSelector fNameSelector = new FilenameSelector();
            fNameSelector.setCasesensitive(false);
            fNameSelector.setName("*.hbm.xml");
            fSet.addFilename(fNameSelector);
            fSet.setProject(pr);
            task.addFileset(fSet);
            task.setOutput(outputDir);
            task.execute();
            ...


Although I had to compile two Ant classes and generate again ant.jar because when calling log() from class 'Project', unusual exceptions were thrown. Then all worked.

-After that, the *.java must be compiled during runtime, calling the main() method from the class 'Javac', or something like that.

-Finally I can call the get() and set() methods from the different classes at my will. Why? My application is used to retrieve and save data from a database but must be useful for every database (not for a specific schema) so I must generate and compile hibernate persistent classes during runtime. I just want to retrieve and save data and I am not interested in associations.

Any idea for the middlegen task?

Thanks and kind regards,
Jose Luis


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I'm curious: Why are you not allowed to call ant, but use the jars ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 1:43 pm 
Newbie

Joined: Mon Aug 23, 2004 9:23 am
Posts: 12
Hello,
Well, if I could, I wouldn't use the jars. I would prefer to use Ant only for the development process. But If I want to use Middlegen and Hibernate, I must use the Ant jars. Is there another way to use hbm2java and middlegen without using Ant jars or even Ant?

I would like not to use Ant because if I want to "insert" (sorry for my english) middlegen and hibernate in my application, I would prefer just using a normal class in a middlegen.jar for example, that could be called.
It is much more clear and if someone wants to use my app, he must install JRE and Ant too or I must include Ant with my app.
As I said, if it was easy enough, I would prefer using Middlegen and Hibernate without Ant.

Errr, two questions by the way:

-I don't know how to fix the exception that is killing me. It is thrown when I do:

MiddlegenTask task = new MiddlegenTask();

It is thrown at line 149 of MiddlegenTask and It is about "Middlegen jar should not be on the System classpath when starting Ant..."

-I have seen a velocity template inside middlegen-hibernate-plugin-2.0-vo.jar called hibernate.vm. Is this the template I must modify to avoid associations?

Thanks and kind regars,
Jose Luis


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 1:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
For the case of hbm2java you can simply call the main method of hbm2java - look into Hbm2JavaTask on how to do it.

With respect to Middlegen I would look into the MiddlegenTask to see how it does it magic.

Build I would really not advocate this stuff ;)

And if you are using ant 1.6.x then you can actually reduce the ant "dead-weight" to almost nothing since they have seperated out the core functionallity into .jar files - so not that big of an dependency.

Regarding the exception - i don't know what it is, but I reckon it's the middlegen task that try to work around ant's "weak" classloading model.

Don't know if you can work around it (besides putting stuff in a separate classloader)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 9:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
jlsanchez wrote:
Hello,
Errr, two questions by the way:

-I don't know how to fix the exception that is killing me. It is thrown when I do:

MiddlegenTask task = new MiddlegenTask();

It is thrown at line 149 of MiddlegenTask and It is about "Middlegen jar should not be on the System classpath when starting Ant..."

-I have seen a velocity template inside middlegen-hibernate-plugin-2.0-vo.jar called hibernate.vm. Is this the template I must modify to avoid associations?

Thanks and kind regars,
Jose Luis


1) If you look into the Middlegen code it checks and throws this exception. Yes it is a classloader workaround.

2) Yes it is (but you using an old(ish) version). Use the R5 release (or better the CVS) version. It is the base for the 2.1 release (which is getting closer to a release).

NOTE: SF has had CVS troubles for a few projects. Unfortunately, Middlegen is one of them - you may have to wait to get to the CVS server.


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