-->
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 and JBuilder
PostPosted: Wed Sep 01, 2004 5:45 am 
Newbie

Joined: Wed Sep 01, 2004 5:31 am
Posts: 18
Hibernate 2.1

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/UserDB</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<!-- Mapping files -->
<mapping resource="client.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Hi all,

Im a total Hibernate newbie and am having some troubles getting hibernate setup in a webapp with JBuilder 9 running the bundled Tomcat 4.1. I'm uncertain where I put the hibernate.properies file and the hibernate.cfg.xml file so that JBuilder finds them. I've tried putting them in /WEB-INF/classes under my webapps server catalogue and also tried putting it in the /Tomcat/work directory and rebuilding without any luck.
When I try to use hibernate from a servlet i get the errors:

1077950 [Thread-3] INFO cfg.Environment - Hibernate 2.1.6
1077950 [Thread-3] INFO cfg.Environment - hibernate.properties not found
1077950 [Thread-3] INFO cfg.Environment - using CGLIB reflection optimizer
1077960 [Thread-3] INFO cfg.Configuration - configuring from resource: /hibernate.cfg.xml
1077960 [Thread-3] INFO cfg.Configuration - Configuration resource: /hibernate.cfg.xml
1078020 [Thread-3] WARN cfg.Configuration - /hibernate.cfg.xml not found

Any help would be greatly appreciated, since I cant find any good information in the Hibernate documentation.

Cheers / J


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 9:02 am 
Newbie

Joined: Wed Sep 01, 2004 5:31 am
Posts: 18
Ok.. my problem has changed. I figured out what the problem was and where to put the the hibernate.cfg.xml file and the other xml files. The server now finds them but i get the error:

15562 [Thread-4] INFO cfg.Environment - using java.io streams to persist binary types
15562 [Thread-4] INFO cfg.Environment - using CGLIB reflection optimizer
15592 [Thread-4] INFO cfg.Configuration - configuring from resource: hibernate.property
15592 [Thread-4] INFO cfg.Configuration - Configuration resource: hibernate.property
15592 [Thread-4] WARN cfg.Configuration - hibernate.property not found

My hibernate.cfg.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/blabla</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url"> jdbc:mysql:/localhost/blabla</property>
<property name="hibernate.connection.username">name</property>
<property name="hibernate.connection.password">pwd</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<!-- Mapping files -->
<mapping resource="client.hbm.xml"/>
</session-factory>
</hibernate-configuration>


And the client.hbm.xml looks like this:


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="se.salespeople.query.hibernate.Client" table="client">
<!-- A int surrogate key. It's automatically generated by Hibernate with the increment pattern. -->
<id name="id" column="id" type="long" unsaved-value="null" access="property">
<column name="id" sql-type="int" not-null="true"/>
<generator class="increment"/>
</id>
<property name="name" type="string"/>
<property name="address" type="string"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 9:33 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
If you use xml configuration this is the code to create SessionFactory (from reference documentation, chapter 3):
Code:
SessionFactory sf = new Configuration().configure().buildSessionFactory();

If you have a DataSource you dont need to specify the driver class, url, username and password in configuration file, they are already present in your datasource configuration.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 10:35 am 
Newbie

Joined: Wed Sep 01, 2004 5:31 am
Posts: 18
I actually got it to work a little more but i have to use

sessionFactory = new Configuration().configure(new File("C:/server/webapp/WEB-INF/classes/hibernate.cfg.xml")).buildSessionFactory();

To specify the config file, it doesn't work without it which I dont understand. Now I get a completely different error. The startup of hibernate stops after these lines:

9583 [Thread-5] INFO cfg.Configuration - instantiating and configuring caches
9834 [Thread-5] INFO impl.SessionFactoryImpl - building session factory

...and nothing more happens. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 01, 2004 10:46 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
Maybe Hibernate can't locate Mapping files


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 3:22 am 
Newbie

Joined: Wed Sep 01, 2004 5:31 am
Posts: 18
i dont think so cos the entire print out looks like this:

7911 [Thread-3] INFO cfg.Configuration - Mapping resource: client.hbm.xml
8142 [Thread-3] INFO cfg.Binder - Mapping class: se.salespeople.query.hibernate.Client -> client
8342 [Thread-3] INFO cfg.Configuration - Configured SessionFactory: null
8342 [Thread-3] INFO cfg.Configuration - processing one-to-many association mappings
8342 [Thread-3] INFO cfg.Configuration - processing one-to-one association property references
8342 [Thread-3] INFO cfg.Configuration - processing foreign key constraints
8392 [Thread-3] INFO dialect.Dialect - Using dialect: net.sf.hibernate.dialect.MySQLDialect
8392 [Thread-3] INFO cfg.SettingsFactory - Maximim outer join fetch depth: 2
8392 [Thread-3] INFO cfg.SettingsFactory - Use outer join fetching: true
8402 [Thread-3] INFO util.NamingHelper - JNDI InitialContext properties:{}
8472 [Thread-3] INFO connection.DatasourceConnectionProvider - Using datasource: java:comp/env/jdbc/db
8502 [Thread-3] INFO transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
9043 [Thread-3] INFO cfg.SettingsFactory - Use scrollable result sets: true
9043 [Thread-3] INFO cfg.SettingsFactory - Use JDBC3 getGeneratedKeys(): true
9043 [Thread-3] INFO cfg.SettingsFactory - Optimize cache for minimal puts: false
9043 [Thread-3] INFO cfg.SettingsFactory - Query language substitutions: {}
9043 [Thread-3] INFO cfg.SettingsFactory - cache provider: net.sf.hibernate.cache.EhCacheProvider
9043 [Thread-3] INFO cfg.Configuration - instantiating and configuring caches
9303 [Thread-3] INFO impl.SessionFactoryImpl - building session factory


btw im using Tomcat connection pooling, I dont know if maybe ive made a mistake there. The server.xml looks like this:


<Server debug="0" port="8001" shutdown="SHUTDOWN">
<Service name="Tomcat-Standalone">
<Connector acceptCount="10" className="org.apache.coyote.tomcat4.CoyoteConnector" connectionTimeout="60000" debug="0" maxProcessors="75" minProcessors="5" port="8000"/>
<Engine debug="0" defaultHost="localhost" name="Standalone">
<Host appBase="P:\project\Tomcat\webapps" debug="0" name="localhost" unpackWARs="true">
<DefaultContext>
<ResourceLink name="linkToGlobalResource" global="simpleValue" type="java.lang.Integer"/>
<Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource" description="User database"/>
<ResourceParams name="jdbc/db">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:mysql://localhost:3306/txl?characterEncoding=8859_1</value>
</parameter>
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<name>username</name>
<value>username</value>
</parameter>
<parameter>
<name>password</name>
<value>pwd</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/db?autoReconnect=true</value>
</parameter>
</ResourceParams>
</DefaultContext>
</Host>
</Engine>
</Service>
</Server>



Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 5:22 am 
Regular
Regular

Joined: Wed Aug 18, 2004 5:16 am
Posts: 69
Location: Modena, Italy
I have not understood the error, you have a malfunction? an exception?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 2:59 am 
Newbie

Joined: Wed Sep 01, 2004 5:31 am
Posts: 18
Yes my problem was that hibernate couldn't locate the hibernate.properties or the hibernate.cfg.xml file, but I got it to work by using an absolute path to my xml file when configuring my session factory:

sessionFactory = new Configuration().configure(new File("P:/webapp/hibernate.cfg.xml")).buildSessionFactory();

So it seems it worked itself out, thanks for taking the time anf trying to help me! Cheers!


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.