-->
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.  [ 3 posts ] 
Author Message
 Post subject: need Hibernate help
PostPosted: Sun Mar 04, 2007 9:54 pm 
Newbie

Joined: Sun Mar 04, 2007 9:41 pm
Posts: 15
Location: SIN
hi everyone

i am new to hibernate can anyone pls guide me thru the basic things to start applcation?

First i want to know is hibernate good choice for standalone application?
To start applicatin, which jar files i need to add in build path?

Thanks


Top
 Profile  
 
 Post subject: Re: need Hibernate help
PostPosted: Mon Mar 05, 2007 2:05 am 
Newbie

Joined: Mon Mar 05, 2007 1:39 am
Posts: 10
Location: Brisbane, Australia
Hmmm, where to start....

Let's start with the JAR: HibernateN.jar (where N is the version number). Drop this in your lib folder.

You're probably going to need to select a bunch of supporting JARs to go with Hibernate, depending on what options you want. For example:
    hsqldb.jar if you want to develop the app in a memory database
    c3p0.jar if you want connection pooling
    cglib.jar is normally required with Hibernate
    ehcache.jar if you want to use this caching option
    jdbc.jar is required to do the connection to the database
    mysql.jar or oracle.jar or whatever your database is


Is Hibernate a good choice? Yes

The basic things to start an application? Hmmm, a stand-alone application. Okay, you've probably read about the XML configuration file - looks a little like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="myapp">

   <class name="Customer" table="app_customer">
      <id name="id" type="integer">
         <generator class="identity" />
      </id>
      <property name="name" type="string" />
      <list name="orders" cascade="all-delete-orphan">
         <key column="_customer" />
         <list-index column="order_no" />
         <one-to-many class="Order" />
      </list>
   </class>
</hibernate-mapping>



You also need a Hibernate context XML document. This defines your database (or connection pool) and the XML configuration file you are going to use:

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
  <description>Configuration of context beans</description>
  <bean id="sessionFactory" class="org.hibernate3.SessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="mappingDirectoryLocations">
      <value>conf/hbm</value>
    </property>
    <property name="hibernateProperties">
      <props>
        <!-- Dialect to use -->
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        <!--  prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop -->

        <!-- isolation level TRANSACTION_READ_UNCOMMITTED -->
        <prop key="hibernate.connection.isolation">1</prop>

        <!-- enable query caching -->
        <prop key="hibernate.cache.use_query_cache">true</prop>

        <!-- standard hibernate properties -->
        <prop key="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.jdbc.use_get_generated_keys">false</prop>
        <prop key="hibernate.jdbc.fetch_size">25</prop>
    <!--<prop key="hibernate.jdbc.batch_size">0</prop>-->
        <prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
        <prop key="hibernate.use_outer_join">true</prop>

      </props>
    </property>

    <!--  Creates/updates the db schema automatically -->
    <property name="schemaUpdate" value="true"/>

  </bean>
  <!-- ====================  Data Source Definitions  =========================== -->
  <!-- Mysql config -->
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass"  value="com.mysql.jdbc.Driver"/>
    <property name="jdbcUrl"      value="jdbc:mysql://localhost:3306/mydbnm"/>
    <property name="user"         value="myusername"/>
    <property name="password"     value="mypassw0rd"/>
  </bean>

<!--
  <!- -  HSql config - - >
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass"  value="org.hsqldb.jdbcDriver"/>
    <property name="jdbcUrl"      value="jdbc:hsqldb:mem:testdb"/>
    <property name="user"         value="myusername"/>
    <property name="password"     value="mypassw0rd"/>
  </bean>
-->
</beans>



Then you start coding your application.

A really good place to start is the Caveat Emptor example Hibernate application. See http://www.hibernate.org/400.html

Let us know how you go with this information...

Cheers
mc

_________________
Murray Collingwood
Focus Computing
http://www.focus-computing.com.au


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 05, 2007 2:40 am 
Newbie

Joined: Sun Mar 04, 2007 9:41 pm
Posts: 15
Location: SIN
Thank you very much for your help.


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