Skip to main content

How to configure hibernate in jsf




How to work with hibernate for creating dao file!!!

Step0:      Create project --> new --> web --> dynamic web project.
Step1:      Right click project properties and then choose Project Facets or type in the box of properties.
Step2:      Choose dynamic web module, java, java persistence, java script toolkit. then apply --> ok
Step3: Persistance.xml file will be created into src folder. Now open Persistance.xml with persistence xml editor. There is
                a. name    : project name
                b. persistence provider and more.
NB: better to copy all contain from actual written Persistance.xml file. which is availabel into autojsfcode projec.

Actual persistance.xml file cotains:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="autojsfcode">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jsftest"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.username" value="root"/>
        <property name="hibernate.connection.password" value=""/>
        <property name="show_sql" value="true" />
     </properties>
</persistence-unit>
</persistence>

For understanding..
---> Name= "autojsfcode"  (project name)
---> Database name = jsftest

Step4:      Right click project properties and then choose java persistence or type in the box of properties.
Step5:      Choose connection: New Mysql --> choose Add connection --> Connection Profile Types: MySql --> click Next.

                a. Database    :         jsftest (database name)
                b. URL         :           jdbc:mysql://localhost:3306/jsftest
                c. User Name:          root
                d. Password: (type if you have)
                e. Click test connection button. (Ping Successfully message will be given)

We have to generate bean java file. For that …
Now we have to create hibernate.cfg.xml file and hibernate.reveng.xml file.

hibernate.cfg.xml

Step6: select right click on project à new à others à type hibernate à Hibernate configuration file.




Then click finish.

hibernate.cfg.xml (must contain)
<?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>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jsftest</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.search.autoregister_listeners">false</property>
        <mapping class="generatedcode.Info" />
    </session-factory>
</hibernate-configuration>

Step6: select right click on project à new à others à type hibernate à Hibernate console Configuration. à do setting à Finish


Now go change mode (Example java, Hibernet, java Browsing, Debug). Right corner of springsource you get this. So select Hibernate. Then left side beside project explorer you will get Hibernate configuration. If does not come then window à reset prospective.

Example : check database

Step7: select right click on project à new à others à type hibernate à Hibernate Reverse Engineering file


Click include à Finish
hibernate.reveng.xml (must contain)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
  <table-filter match-catalog="jsftest" match-name="info"/>
</hibernate-reverse-engineering>

Step8: make automatically generate code  for that click picture option and then choose Hibernate code generation configuration




……………..
Create new record just beside Red Cross symbol and do setting as per image.
Now run. Code will automatically generate.


After generating code you get error in java file.
For solving that error: keep your mouse on import package. Then

Then organize import click.
Again above class write this code @Entity
@Table(name = "info", catalog = "jsftest")

Change db : jsftest to your db and name info to your info

Date: 21-12-11
=============================== Done =====================================















































Comments

Post a Comment

Popular posts from this blog

How to get iRecruitment Vacancy details in Oracle HRMS before Vacancy is approved.

Generally details of Vacancies created in Oracle iRecruitment are store in ‘PER_ALL_VACANCIES’ table. But you cant see the vacancy details in ‘PER_ALL_VACANCIES’ table if the vacancy is NOT approved . Where does Vacancy details get stored  before Approval/Rejection As soon as vacancy is created the vacancy related data goes and resides in some temporary tables. This data is retained within the temporary tables until the vacancy is either Rejected or Approved. These temporary table names begin with name ‘HR_API%’. Not only vacancies but also other Self Service HRMS details are stored in temporary table before completion of it entire transaction, i.e either Approved or Rejected. Coming to iRecruitment vacancy, the data entered by the user is either just stored within one table HR_API_TRANSACTIONS or within HR_API_TRANSACTION_VALUES. The entire data entered by the user is captured in a CLOB column of HR_API_TRANSACTIONS. The data is captured into this CLOB Column be...

How to deploy Oracle Custom Application developed in OAF in Oracle Application Server

Step 1:Create your necessary Database Obejcts i.e.Tables,Views,Sequences,Synonims in Apps schema. i) CREATE TABLE apps.XXGP_JDMS_APP_TABLE (   JD_ID               VARCHAR2 ( 100 BYTE),   APP_USER_NAME       VARCHAR2 ( 100 BYTE),   APP_STATUS          VARCHAR2 ( 100 BYTE),   APP_LEVEL           NUMBER ,   APPROVER_COMMENTS   VARCHAR2 ( 1000 BYTE),   NOTIFICATION_ID     VARCHAR2 ( 100 BYTE),   CREATED_BY          NUMBER ,   CREATION_DATE       DATE ,   LAST_UPDATE_LOGIN   NUMBER ,   LAST_UPDATED_BY     NUMBER ,   LAST_UPDATE_DATE    DATE ) ii) DROP SEQUENCE APPS . GP_JDMS_TRX_SEQ ; CREATE SEQUEN...

Query for Employee's Time Card information retrieval

SELECT DISTINCT paaf.assignment_id, hshwf.date_worked,                          TO_CHAR (hshwf.date_worked, 'YYYY') YEAR,                          TO_CHAR (hshwf.date_worked, 'Month') MONTH,                          papf.employee_number,                          hshwf.time_in, hshwf.time_out, hshwf.hours,                          --petf.element_name,                          (select petf1.element_name                           from hr.pay_element_types_f petf1                     ...