Wednesday, October 11, 2017

Hibernate Annotations Approach


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

        <!-- Database connection properties - Driver, URL, user, password -->
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@</property>
        <property name="hibernate.connection.username">DLAUDIT</property>
        <property name="hibernate.connection.password">DLAUDIT</property>
        <!-- Connection Pool Size -->
        <property name="hibernate.connection.pool_size">10</property>
        <!-- org.hibernate.HibernateException: No CurrentSessionContext configured! -->
        <property name="hibernate.current_session_context_class">thread</property>
        <!-- Outputs the SQL queries, should be disabled in Production -->
        <property name="hibernate.show_sql">true</property>
        <property name="format_sql">true</property>
        <!-- Dialect is required to let Hibernate know the Database Type, MySQL, Oracle etc
            Hibernate 4 automatically figure out Dialect from Database Connection Metadata -->
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>

        <!-- mapping file, we can use Bean annotations too -->
        <mapping class="com.hiberante.api.annotations.Account" />


package com.hiberante.api.annotations;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

public class Account {

private Integer id;

@Column(name = "GUI")
private String gui;

private String firstName;

private String lastName;

private Integer age;

public Integer getId() {
return id;
public void setId(Integer id) { = id;
public String getGui() {
return gui;
public void setGui(String gui) {
this.gui = gui;
public String getFirstName() {
return firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
public String getLastName() {
return lastName;
public void setLastName(String lastName) {
this.lastName = lastName;
public Integer getAge() {
return age;
public void setAge(Integer age) {
this.age = age;