-->
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: Hibernate plugin for Eclipse - empty items
PostPosted: Sun Aug 06, 2006 1:23 am 
Newbie

Joined: Sun Aug 06, 2006 12:55 am
Posts: 11
I have recently installed the latest version of Hibernate tools in Eclipse 3.2 and am having a couple of probs.

I have followed the tutorial at http://www.hibernate.org/hib_docs/tools ... ugins.html and things are mostly working.

However, when I open my Hibernate Console there are 3 nodes, Configuration, Session Factory and Database

- Database opens fine and shows the schema node and then all the tables in my MYSQL 5.0 db
- when I open the configuration node it has no child nodes
- when I try to open the session factory node i see the text 'pending' appear for half a second and then it disappears. The Eclipse error log shows the warning


"WARN Worker-3 org.hibernate.impl.SessionFactoryObjectFactory - Could not bind factory to JNDI" and the first few lines of the stacktrace are
Code:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
   at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
   at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
   at javax.naming.InitialContext.getNameParser(Unknown Source)



Its kind of weird because the code generation tools seem to be working fin in that they are able to connect to the db and generate my domain classes and hbm.xml files OK.

Unfortunately it seems the error I am getting is stopping me from using the Hibernate Entity Model (which is always blank), Hibernate Dynamic SQL Preview or any of the other handy looking plugin tools.

Anyone else had this problem? Anyone know how to solve it?

My hibernate.cfg.xml is below. I have tried to remove and/or specify the hibernate.default_catalog and hibernate.default_schema properties below but it doesnt seem to make a difference.

Thanks.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="cricket-session">
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">cricket</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/cricket</property>
        <property name="hibernate.connection.username">cricket</property>
        <property name="hibernate.default_catalog">cricket</property>
        <property name="hibernate.default_schema">cricket</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    </session-factory>
</hibernate-configuration>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 2:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you have 2 issues:

#1 is that you are apparently pointing to a cfg.xml with a jndi name which will take some time if jndi is not available (which it isn't under eclipse)

#2 your cfg.xml does not list any mappings so hibernate shows the correct thing: that no mappings are defined.

solution: put in your mappings (or let the reverseengineering do if for you by selecting the hibernate cfg exporter)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 6:32 pm 
Newbie

Joined: Sun Aug 06, 2006 12:55 am
Posts: 11
max wrote:
you have 2 issues:

#1 is that you are apparently pointing to a cfg.xml with a jndi name which will take some time if jndi is not available (which it isn't under eclipse)

#2 your cfg.xml does not list any mappings so hibernate shows the correct thing: that no mappings are defined.

solution: put in your mappings (or let the reverseengineering do if for you by selecting the hibernate cfg exporter)


Thanks - those tips helped me out, although I still dont think I have it setout quite correctly...

Adding mapping elements manually to my cfg.xml file, or allowing the code generator to insert the mapping elements didnt seem to work. Whenever I tried to open my configuration in the Hibernate Console I always got an error saying the console couldnt locate the mapping files specified in cfg.xml

eg.
Code:
<mapping resource="com/mk/cricket/model/DivisionType.hbm.xml" />

would cause
Code:
org.hibernate.MappingException: Resource: com/mk/cricket/model/DivisionType.hbm.xml not found


If I removed all mapping elements from my cfg.xml file, and instead added them via the console config UI "Additional Mapping Files (not listed in cfg.xml" then the 'Configuration' node populated correctly.

Similarly I needed to add the path to my com/mk/cricket/model src directory in the "Classpath (only add path for POJO and driver...) so the 'Session Factory' node also populated OK, otherwise I'd get

Code:
org.hibernate.MappingException: entity class not found: com.mk.cricket.model.Person
   at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:103)


Its as though the hibernate console doesnt know anything about the classpath of my Eclipse project or something. Is this normal? Is there something I need to tweak so the hibernate console can automatically locate my hibernate mapping files and my generated class files?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 1:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
As listed in the docs and on the console configuration screen you need to specify the classpath (excluding any hibernate references) so that the pojo's and resources can be located.

A console configuration can be used in multiple projects thus it (at the moment) doesn't know which project to "trust".

Furthermore if i were to "trust" a project I would have to filter the classpath from jars/classes that would collide with the hibernate version the tool is running against....we might do that in the future, but right now I give the user the control to avoid any spookey hard to find class aliasing errors.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 1:14 am 
Newbie

Joined: Sun Aug 06, 2006 12:55 am
Posts: 11
max wrote:
As listed in the docs and on the console configuration screen you need to specify the classpath (excluding any hibernate references) so that the pojo's and resources can be located.

A console configuration can be used in multiple projects thus it (at the moment) doesn't know which project to "trust".

Furthermore if i were to "trust" a project I would have to filter the classpath from jars/classes that would collide with the hibernate version the tool is running against....we might do that in the future, but right now I give the user the control to avoid any spookey hard to find class aliasing errors.


Thanks Max. The classpath POJO config does make sense. Just wanted to double check I wasnt doing anything crazy.

What about my problem regarding the <mapping> elements causing problems when configured in hibernate.cfg.xml? Is that expected behaviour?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 1:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the mapping resource tag uses the classpath just as when loading classes thus you also need to make sure those files are in the console configuration classpath.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 1:40 am 
Newbie

Joined: Sun Aug 06, 2006 12:55 am
Posts: 11
max wrote:
the mapping resource tag uses the classpath just as when loading classes thus you also need to make sure those files are in the console configuration classpath.


Ahhh. Got it now. Thanks. So all I needed to do to get the <mapping> elements working was to add the root output directory (ie build/classes) to the hibernate console classpath.

Excellent. Thanks for helping out a clueless newb.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 2:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
exactly, and for future reference if you select the java project (or a file within it) before starting the wizard it will automatically pick up that output classpath and use it.

_________________
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.