|Home |Login |Registration |Struts Step by Step Tutorial |Hibernate Step by Step Tutorial |Spring Step by Step Tutorial |JSP Step by Step Tutorial |JDBC Step by Step Tutorial |Web Services Step by Step Tutorial |EJB fundamentals | ORACLE Step by Step Tutorial | SCJP 5.0 and SCJP 6.0 Study Guide | SCWCD 5.0 Study Guide | SCJP Tips
Java mock test | SCJP mock test | SCJP DUMP | SCBCD mock test |Java online test exam | JSP online test | ORACLE online test | Hibernate online test | Servlet online test | Struts online test | EJB online test | C online test | C++ online test | Aptitude online test

Java interview questions | JSP interview questions | ORACLE interview questions | Hibernate interview questions | Servlet interview questions | Struts interview questions | JDBC interview questions | C/C++ interview questions | Spring interview questions | JMS interview questions | Informatica interview questions | EJB interview questions | OOPS and Design Pattern interview questions
1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc) JobsJobs and Walkins

 

Recent Questions

!!! Hibernate Frequently Asked Questions !!!

Hibernate setup using .cfg.xml file ?

SCJP 1.5/1.6 Exam Kit

!!!Answer!!!- From Technical Expert

The XML configuration file is by default expected to be in the root o your CLASSPATH. Here is an example:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory
name="java:hibernate/SessionFactory">
<!-- properties -->
<property name="connection.datasource">java:/comp/env/jdbc/MyDB</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<!-- mapping files -->
<mapping resource="org/hibernate/auction/Cost.hbm.xml"/>
</session-factory>
</hibernate-configuration>
As you can see, the advantage of this approach is the externalization of the mapping file names to configuration.
The hibernate.cfg.xml is also more convenient once you have to tune the Hibernate cache. Note that is
your choice to use either hibernate.properties or hibernate.cfg.xml, both are equivalent, except for the
above mentioned benefits of using the XML syntax.
With the XML configuration, starting Hibernate is then as simple as
SessionFactory sf = new Configuration().configure().buildSessionFactory();
You can pick a different XML configuration file using
SessionFactory sf = new Configuration()
.configure("catdb.cfg.xml")
.buildSessionFactory();

Cost.hbm.xml -----> looks like

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

<hibernate-mapping>
<class name="com.bean.Cost" table="COST">

<id name="id" column="ID">
</id>
<property name="isQueued" type="int" column="IS_QUEUED"/>
<property name="queueDate" type="timestamp" column="QUEUE_DATE"/>
<property name="lastModifiedDate" type="timestamp" column="LAST_MODIFIED_DATE"/>
<property name="lastModifiedBy" column="LAST_MODIFIED_BY"/>
<property name="amount" column="AMOUNT" type="double"/>
<property name="currencyCode" column="CURRENCY_CODE" />
<property name="year" column="YEAR"/>
<property name="quarter" column="QUARTER"/>
<property name="costModFlag" type="int" column="COST_MOD_FLAG"/>
<property name="parentId" column="PARENT_ID"/>
<property name="oldParentId" column="OLD_PARENT_ID"/>
<property name="parentIdModFlag" type="int" column="PARENT_ID_MOD_FLAG"/>
<property name="dateIncurred" type="timestamp" column="DATE_INCURRED"/>
<property name="USDAmount" column="USD_AMOUNT" type="double"/>
<property name="isDeleted" type="int" column="IS_DELETED"/>
</class>

</hibernate-mapping>

Answered By : null Replied Date : Apr 6 2012
Answer :


Answered By : null Replied Date : Mar 8 2012
Answer :


Answered By : null Replied Date : Mar 5 2012
Answer :


Answered By : null Replied Date : Feb 10 2012
Answer :


Answered By : null Replied Date : Jan 15 2012
Answer :


Answered By : null Replied Date : Dec 12 2011
Answer :


Answered By : null Replied Date : Dec 11 2011
Answer :


Answered By : null Replied Date : Dec 6 2011
Answer :


Answered By : null Replied Date : Dec 5 2011
Answer :


Answered By : null Replied Date : Dec 1 2011
Answer :


Answered By : null Replied Date : Nov 4 2011
Answer :


Answered By : null Replied Date : Oct 21 2011
Answer :


Answered By : null Replied Date : Sep 25 2011
Answer :


Answered By : null Replied Date : Aug 12 2011
Answer :


Answered By : null Replied Date : Aug 11 2011
Answer :


Answered By : null Replied Date : Jul 23 2011
Answer :


Answered By : null Replied Date : Jul 5 2011
Answer :


Answered By : null Replied Date : Jun 18 2011
Answer :


Answered By : null Replied Date : May 23 2011
Answer :


Answered By : null Replied Date : May 23 2011
Answer :


Answered By : null Replied Date : May 10 2011
Answer :


Answered By : null Replied Date : May 6 2011
Answer :


Answered By : null Replied Date : May 3 2011
Answer :


Answered By : null Replied Date : May 2 2011
Answer :


Answered By : null Replied Date : Mar 29 2011
Answer :


Answered By : null Replied Date : Mar 29 2011
Answer :


Answered By : null Replied Date : Mar 23 2011
Answer :


Answered By : null Replied Date : Mar 14 2011
Answer :


Answered By : null Replied Date : Feb 26 2011
Answer :


Answered By : null Replied Date : Feb 19 2011
Answer :


Answered By : null Replied Date : Feb 15 2011
Answer :


Answered By : null Replied Date : Jan 27 2011
Answer :


Answered By : null Replied Date : Jan 25 2011
Answer :


Answered By : null Replied Date : Jan 21 2011
Answer :


Answered By : null Replied Date : Jan 21 2011
Answer :


Answered By : null Replied Date : Jan 20 2011
Answer :


Answered By : null Replied Date : Jan 15 2011
Answer :


Answered By : null Replied Date : Dec 26 2010
Answer :


Answered By : null Replied Date : Dec 23 2010
Answer :


Answered By : null Replied Date : Dec 19 2010
Answer :


Answered By : null Replied Date : Dec 18 2010
Answer :


Answered By : null Replied Date : Dec 18 2010
Answer :


Answered By : null Replied Date : Dec 12 2010
Answer :


Answered By : null Replied Date : Dec 8 2010
Answer :


Answered By : null Replied Date : Dec 3 2010
Answer :


Answered By : null Replied Date : Dec 1 2010
Answer :


Answered By : null Replied Date : Nov 29 2010
Answer :


Answered By : null Replied Date : Nov 27 2010
Answer :


Answered By : null Replied Date : Nov 25 2010
Answer :


Answered By : null Replied Date : Nov 25 2010
Answer :


Answered By : null Replied Date : Nov 23 2010
Answer :


Answered By : null Replied Date : Nov 23 2010
Answer :


Answered By : null Replied Date : Nov 22 2010
Answer :


Answered By : null Replied Date : Nov 20 2010
Answer :


Answered By : null Replied Date : Aug 21 2010
Answer :


Answered By : null Replied Date : Aug 14 2010
Answer :


Answered By : null Replied Date : Aug 12 2010
Answer :


Answered By : null Replied Date : Aug 11 2010
Answer :


Answered By : null Replied Date : Aug 8 2010
Answer :


Answered By : null Replied Date : May 3 2012
Answer :


Answered By : null Replied Date : May 8 2012
Answer :


Answered By : null Replied Date : Jun 7 2012
Answer :


Answered By : null Replied Date : Jun 18 2012
Answer :


Answered By : null Replied Date : Jul 12 2012
Answer :


Answered By : null Replied Date : Jul 31 2012
Answer :


Answered By : null Replied Date : Aug 4 2012
Answer :


Answered By : null Replied Date : Aug 4 2012
Answer :


Answered By : null Replied Date : Aug 12 2012
Answer :


Answered By : null Replied Date : Sep 12 2012
Answer :


Answered By : null Replied Date : Oct 10 2012
Answer :


Answered By : null Replied Date : Nov 2 2012
Answer :


Answered By : null Replied Date : Nov 28 2012
Answer :


Answered By : null Replied Date : Dec 26 2012
Answer :


Answered By : null Replied Date : Mar 18 2013
Answer :


Answered By : null Replied Date : Mar 25 2013
Answer :


 

You can also contribute to this answer:

Your Name:
Answer:

 
Ask Question and get answer from Expert.
View Answers List from Expert.

The information you are posting should be related to java and ORACLE technology. Not political.