-->
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.  [ 10 posts ] 
Author Message
 Post subject: can't find .hbm.xml file
PostPosted: Tue Jan 06, 2004 10:01 pm 
Newbie

Joined: Tue Jan 06, 2004 12:49 pm
Posts: 5
Hello,
I am hoping to build a stand alone Hibernate application. The problem is that it can't find the .hbm.xml file.

I have the following main method:

package test;

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.Configuration;
import VO.Action;
import org.apache.log4j.*;


/**
* Title:
* Description:
* Copyright: Copyright (c) 2003
* Company:
* @author
* @version 1.0
*/

public class TestHibernate {

public TestHibernate() {
}
public void doIt() {
try {

Configuration cfg = new Configuration();
cfg.addClass(Action.class);
SessionFactory factory = cfg.buildSessionFactory();
} catch (Exception e) {
System.out.println("error- "+ e);
}
}


And in folder VO I have an Action class, and I also have Action.hbm.xml.
Yet, I get this result:

C:\JBuilder4\jdk1.3\bin\javaw -classpath "C:\Documents and Settings\Michel de Lange\jbproject\Swing\classes;C:\log4j\jakarta-log4j-1.2.8\dist\lib\log4j-1.2.8.jar;C:\mm\mm.mysql-2.0.12\mm.mysql-2.0.12-bin.jar;C:\hibernate-2.1\hibernate2.jar;C:\hibernate-2.1\lib\dom4j.jar;C:\hibernate-2.1\lib\commons-collections.jar;C:\hibernate-2.1\lib\commons-dbcp.jar;C:\hibernate-2.1\lib\commons-lang.jar;C:\hibernate-2.1\lib\commons-logging.jar;C:\hibernate-2.1\lib\commons-pool.jar;C:\JBuilder4\jdk1.3\demo\jfc\Java2D\Java2Demo.jar;C:\JBuilder4\jdk1.3\jre\lib\i18n.jar;C:\JBuilder4\jdk1.3\jre\lib\jaws.jar;C:\JBuilder4\jdk1.3\jre\lib\rt.jar;C:\JBuilder4\jdk1.3\jre\lib\sunrsasign.jar;C:\JBuilder4\jdk1.3\lib\dt.jar;C:\JBuilder4\jdk1.3\lib\tools.jar" test.TestHibernate
0 [main] INFO net.sf.hibernate.cfg.Environment - Hibernate 2.1.1

20 [main] INFO net.sf.hibernate.cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.hsqldb.jdbcDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, hibernate.connection.url=jdbc:hsqldb:., hibernate.connection.password=, hibernate.connection.pool_size=1}

300 [main] INFO net.sf.hibernate.cfg.Environment - using java.io streams to persist binary types

300 [main] INFO net.sf.hibernate.cfg.Environment - using CGLIB reflection optimizer

751 [main] INFO net.sf.hibernate.cfg.Environment - JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled

751 [main] INFO net.sf.hibernate.cfg.Environment - using workaround for JVM bug in java.sql.Timestamp

1342 [main] INFO net.sf.hibernate.cfg.Configuration - Mapping resource: VO/Action.hbm.xml

error- net.sf.hibernate.MappingException: Resource: VO/Action.hbm.xml not found


What am I doing wrong? Any help is much appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 11:54 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Check out http://www.hibernate.org/hib_docs/reference/html/session-configuration.htmlhttp://www.hibernate.org/hib_docs/reference/html/session-configuration.html


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 6:24 am 
Newbie

Joined: Tue Jan 06, 2004 12:49 pm
Posts: 5
Hi,

That is not found either! It's not my lucky day. Anyway, I did figure it out immediately after I went to bed. It was a misunderstanding on my part of what is the classpath in JBuilder. After I put the .xml file in the directory where the class files go, it is found. Not that it helps much, because now I have this one:

java.lang.ExceptionInInitializerError: java.lang.NullPointerException at java.util.HashMap.put(HashMap.java:327)

at net.sf.hibernate.type.TypeFactory.<clinit>(TypeFactory.java:50)

at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:894)

at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:403)

at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:257)

at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)

at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)

at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)

at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:322)

at test.TestHibernate.doIt(TestHibernate.java:25)

at test.TestHibernate.main(TestHibernate.java:42)

Exception in thread "main"


Cheers,


Michel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:52 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
sgwood wrote:




Sorry, bad typing...

Try

http://www.hibernate.org/hib_docs/reference/html/session-configuration.html

and

http://www.hibernate.org/hib_docs/reference/html/session-configuration.html



Your latest problem is again a classpath issue - you don;t have all the required JARs. Look at lib/README.txt in your Hibernate distribution.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 9:58 am 
Newbie

Joined: Tue Jan 06, 2004 12:49 pm
Posts: 5
Hello,

I do have them all. I have all jars in the hibernate/lib as well as hibernate2.jar on my classpath.

One thing that puzzles me, but I don't know whether this is related is this: If there are 2 databases in hibernate.properties, how does hibernate know which to choose?

Best regards,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:01 am 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Post your hibernate.properties.


Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:25 am 
Newbie

Joined: Tue Jan 06, 2004 12:49 pm
Posts: 5
Here it is:



######################
### Query Language ###
######################

## define query language constants / function names

hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'



#################
### Platforms ###
#################

## MySQL

#hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
#hibernate.connection.driver_class org.gjt.mm.mysql.Driver
##hibernate.connection.driver_class com.mysql.jdbc.Driver
#hibernate.connection.url jdbc:mysql:///mydb
#hibernate.connection.username root
#hibernate.connection.password


#################################
### Hibernate Connection Pool ###
#################################

hibernate.connection.pool_size 1



###########################
### C3P0 Connection Pool###
###########################

#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.validate false



###################################
### Apache DBCP Connection Pool ###
###################################

## connection pool

#hibernate.dbcp.maxActive 100
#hibernate.dbcp.whenExhaustedAction 1
#hibernate.dbcp.maxWait 120000
#hibernate.dbcp.maxIdle 10

## prepared statement cache

#hibernate.dbcp.ps.maxActive 100
#hibernate.dbcp.ps.whenExhaustedAction 1
#hibernate.dbcp.ps.maxWait 120000
#hibernate.dbcp.ps.maxIdle 10

## optional query to validate pooled connections:

#hibernate.dbcp.validationQuery select 1 from dual
#hibernate.dbcp.testOnBorrow true
#hibernate.dbcp.testOnReturn false



##############################
### Proxool Connection Pool###
##############################

## Properties for external configuration of Proxool

hibernate.proxool.pool_alias pool1

## Only need one of the following

#hibernate.proxool.existing_pool true
#hibernate.proxool.xml proxool.xml
#hibernate.proxool.properties proxool.properties

## Or, alternatively, all of these
## Standard configuration properties of Proxool

#hibernate.proxool.house-keeping-sleep-time 30000
#hibernate.proxool.house-keeping-test-sql
#hibernate.proxool.maximum-connection-count 4
#hibernate.proxool.maximum-connection-lifetime 4
#hibernate.proxool.simultaneous-build-throttle 2
#hibernate.proxool.maximum-active-time 500
#hibernate.proxool.minimum-connection-count 2
#hibernate.proxool.fatal-sql-exception
#hibernate.proxool.prototype-count
#hibernate.proxool.statistics
#hibernate.proxool.recently-started-threshold
#hibernate.proxool.overload-without-refusal-lifetime



#################################
### Plugin ConnectionProvider ###
#################################

## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)

#hibernate.connection.provider_class net.sf.hibernate.connection.DriverManagerConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.C3P0ConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DBCPConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.ProxoolConnectionProvider



#######################
### Transaction API ###
#######################

## the Transaction API abstracts application code from the underlying JTA or JDBC transactions

#hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
#hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory


## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
## default is java:comp/UserTransaction
## you do NOT need this setting if you specify hibernate.transaction.manager_lookup_class

#jta.UserTransaction jta/usertransaction
#jta.UserTransaction javax.transaction.UserTransaction
#jta.UserTransaction UserTransaction


## to use JCS caching with JTA, Hibernate must be able to obtain the JTA TransactionManager

#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.JBossTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.OrionTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.ResinTransactionManagerLookup



##############################
### Miscellaneous Settings ###
##############################

## print all generated SQL to the console

#hibernate.show_sql true


## auto schema export

#hibernate.hbm2ddl.auto create-drop
#hibernate.hbm2ddl.auto create
#hibernate.hbm2ddl.auto update


## specify a JDBC isolation level

#hibernate.connection.isolation 4


## set the JDBC fetch size

#hibernate.jdbc.fetch_size 25


## set the maximum JDBC 2 batch size (a nonzero value enables batching)

hibernate.jdbc.batch_size 0


## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)

#hibernate.jdbc.use_scrollable_resultset true


## use streams when writing binary types to / from JDBC

hibernate.jdbc.use_streams_for_binary true


## specify a default schema for unqualified tablenames

#hibernate.default_schema test


## use a custom stylesheet for XML generation (if not specified, hibernate-default.xslt will be used)

#hibernate.xml.output_stylesheet C:/Hibernate/net/sf/hibernate/hibernate-default.xslt


## enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default)

#hibernate.use_outer_join false


## set the maximum depth of the outer join fetch tree

hibernate.max_fetch_depth 1


## enable CGLIB reflection optimizer (enabled by default)

#hibernate.cglib.use_reflection_optimizer false


## enable the query cache

#hibernate.cache.use_query_cache true


## choose a cache implementation

#hibernate.cache.provider_class net.sf.ehcache.hibernate.Provider
#hibernate.cache.provider_class net.sf.hibernate.cache.EmptyCacheProvider
hibernate.cache.provider_class net.sf.hibernate.cache.HashtableCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.TreeCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.OSCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.JCSCacheProvider
#hibernate.cache.provider_class net.sf.hibernate.cache.SwarmCacheProvider


############
### JNDI ###
############

## specify a JNDI name for the SessionFactory

#hibernate.session_factory_name hibernate/session_factory


## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
## is the best approach in an application server

#file system
#hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
#hibernate.jndi.url file:/

#WebSphere
#hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
#hibernate.jndi.url iiop://localhost:900/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
m7373 wrote:
One thing that puzzles me, but I don't know whether this is related is this: If there are 2 databases in hibernate.properties, how does hibernate know which to choose?Best regards,

You have to configure hibernate is an hibernate.cfg.xml file

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:46 am 
Newbie

Joined: Tue Jan 06, 2004 12:49 pm
Posts: 5
Must I have 2 files:
1) hibernate.properties
2) hibernate.cfg.xml
?

What must I put in hte cfg.xml file?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You'll have 2 cfg.xml (1 for each DB) and 1 .properties
I usually put everything in cfg.xml
I use hibernate.properties for System level proeprties (see reference guide)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.