-->
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.  [ 8 posts ] 
Author Message
 Post subject: Tutorial on using JBoss IDE (eclipse) and hibernate
PostPosted: Wed Nov 15, 2006 9:03 am 
Newbie

Joined: Wed Nov 15, 2006 8:51 am
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

To all,

I just installed the jboss ide (plugin) on eclipse 3.1; are there any complete tutorial in using the "hibernate tools" to build and execute projects using hibernate? (eg. how to generate .hbm.xml files, how to generate POJO from a DB connection)

I have followed the help on hibernate tools :
http://www.hibernate.org/hib_docs/tools ... ugins.html

but I can't run the program, there were some errors like can't find the hibernate.cfg.xml, haven't configure a SessionFactory and others...

PS. I am wondering maybe hibernate tools is sort of a "starter" and would create some basic xml files only; while for the remaining config information, I might need to add them back .... or maybe I am not using it correctly!

From Jason (Kusanagihk)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 9:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I'm not sure what you are asking for ?

The docs shows how to create cfg.xml and how you can use it to create a console configuration so you can run queries and code generation from inside eclipse.

You don't precisly say what error you are seeing, but you mention "not being able to find..." and that indicates to me you did not configure the classpath correctly in the console configuration.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 9:57 pm 
Newbie

Joined: Wed Nov 15, 2006 8:51 am
Posts: 12
More information, hopefully:

The 1st thing is that the plugin just create an incomplete cfg.xml file, eg. the mapping resources are not attached (though I'm not sure if the plugin could attach these information automatically or not)

The 2nd thing is that in order to run the program; I need to add back the <mapping /> tags; and a tag on
<property name="current_session_context_class">thread</property>
again, I am not sure if all these entries could be handled by the plugin or not (like there is some action triggered to integrate the .hbm.xml file information to the .cfg.xml file)

The 3rd thing is within the hibernate console perspective; I could not execute HQL since hibernate.cfg.xml is incomplete at the first place; after adding back the <mapping/> tags, things seem to be much better, but still I can't execute HQL --> errors like " customer is not mapped " still occured


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 11:17 pm 
Newbie

Joined: Wed Nov 15, 2006 8:51 am
Posts: 12
Oh hi, I guess I've most of the answers after a few trial and error in using the hibernate tools plugin (eclipse)

Actually I could get nearly all configurations setup by choosing various exporter options under the "hibernate code generation" screen;

the options I've chosen are :
Domain code (.java),
Hibernate XML Mappings (.hbm.xml),
Hibernate XML Configurations (.cfg.xml)

After running the exporter, nearly everythings been setup; except adding back the property tag on "hibernate.current_session_context_class" and add back a log4j.properties file; then I could run the programs finally.

But as the hibernate perspective, I still could not get all the functions working; like the "Hibernate Entity Model" has nothing showing; the HQL queries are still unable to run (have exceptions like the table is not mapped)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 5:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
kusanagihk wrote:
The 1st thing is that the plugin just create an incomplete cfg.xml file, eg. the mapping resources are not attached (though I'm not sure if the plugin could attach these information automatically or not)


Well, when you create a cfg.xml then it is assumed you are starting from scratch and thus doesn't have any hbm.xml.

If you already have a cfg.xml why don't you just use that ?

note: selecting cfg.xml generation in the exporter will generate a cfg.xml with mappings.

Quote:
The 2nd thing is that in order to run the program; I need to add back the <mapping /> tags; and a tag on
<property name="current_session_context_class">thread</property>
again, I am not sure if all these entries could be handled by the plugin or not (like there is some action triggered to integrate the .hbm.xml file information to the .cfg.xml file)


Again, you are saying "add back" as if you already had a cfg.xml so why did you not just use that ?

Maybe you are looking for a feature of autoscanning the projects for hbm.xml and have us auto-add that ? That could possibly be done yes; an alternative is to use hibernate entitymanager to get runtime autoscanning so you don't need to add them at all.

Quote:
The 3rd thing is within the hibernate console perspective; I could not execute HQL since hibernate.cfg.xml is incomplete at the first place; after adding back the <mapping/> tags, things seem to be much better, but still I can't execute HQL --> errors like " customer is not mapped " still occured


If customer is not mapped then its because customer is not mapped....something is missing in the mappings.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 5:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
kusanagihk wrote:
Oh hi, I guess I've most of the answers after a few trial and error in using the hibernate tools plugin (eclipse)

Actually I could get nearly all configurations setup by choosing various exporter options under the "hibernate code generation" screen;

the options I've chosen are :
Domain code (.java),
Hibernate XML Mappings (.hbm.xml),
Hibernate XML Configurations (.cfg.xml)

After running the exporter, nearly everythings been setup; except adding back the property tag on "hibernate.current_session_context_class" and add back a log4j.properties file; then I could run the programs finally.


Hibernate doesn't delete a log4j.properties so why you say "add back" i don't get ;)

Quote:
But as the hibernate perspective, I still could not get all the functions working; like the "Hibernate Entity Model" has nothing showing; the HQL queries are still unable to run (have exceptions like the table is not mapped)


The entity model show something if you have selected the configuratio AND there is something in it.

If hql doesn't work then its because your hql is wrong or mappings are wrong.

What is the exception ?

Did you remember to refresh/create a new sesionfactory after you regenerated the code ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 10:24 pm 
Newbie

Joined: Wed Nov 15, 2006 8:51 am
Posts: 12
Hi Max,

I think the main point is that I haven't a clear idea on how the plugin works and what it could assist in the project earlier.

Since I only have experience in using hibernate under console mode (ie. not using eclipse) therefore I started to new a "hibernate configuratio file" and not using the "exporter" utilities instead; that's why I mentioned I need to "add back" the mappings afterwards :-) But as for now, I used the "exporter" utility to auto-scann the mappings for me and also created the hibernate.cfg.xml file instead.

As for HQL problems: the 1st warning I have received is that on the "Hibernate configuration" tab under the hibernate perspective; "<SessionFactory error: component class not found: CLASS_NAME>"
but the question is the class it specified is generated by the exporter and it is available in the project (wonder what was wrong) As I've got this warning, I could not open a new HQL scrap page to try the HQL. (not sure if it is a bug or not, I've opened a HQL scrap page under this situation some time earlier; but could not do it anymore now...)

Really thanks for your help.

From Jason (Kusanagihk)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 4:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Well if you use the "autoscan" feature as you call it then your console configuration apparently has no cfg.xml listed + it lists all the pre-existing hbm.xml files as the mapping files to add.

Thus when you generate it will read the pre-existing hbm.xml files and generate a cfg.xml that you probably ain't using ?

But in any case your error indicates to me that the component class is either not compiled or not listed in the console configuration classpath.

p.s. all the classpath issues will go away in the next release since we there start using the projects classpath by default.

_________________
Max
Don't forget to rate


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