Code Monkey home page Code Monkey logo

hibernate_quickstart's Introduction

hibernate_quickstart

The project is a simple prototype that you can use to

  • embed a DB in the project
  • configure hibernate

It sets up an embedded DB with some basic schema that hibernate uses to access.

Requirements

Instructions

Clone this git repository

git clone [email protected]:username/hibernate_quickstart.git

Start Derby in network mode startNetworkServer

Execute the maven pom

cd hibernate_quickstart
mvn clean install exec:java

This will call the HibernateMain class which calls the Hibernate DAO layer.

##What it does

  • fires up an embedded DB
  • populates the DB with some initial data
  • executes some Hibernate code against that DB
  • program ends and DB gets garbaged cleaned up

##How it works

To fire up the DB we use instruct Spring 4 to start up and configure a Derby DB

<jdbc:embedded-database id="dataSource" type="DERBY">
    <jdbc:script location="classpath:db/sql/create-db.sql" />
    <jdbc:script location="classpath:db/sql/insert-data.sql" />
</jdbc:embedded-database>

This gets executed when the ApplicationContext is initialised in the HibernateMain class.

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

Traditionally we set up hibernate from a properties file that gets pulled into a JNDI ServiceRegistry that hibernate configuration draws upon.

In our case, we have a datasource already created (by Spring) so we need to programmatically add it to the hibernate configuration. The simplest way to do this is just to generate a session out of this datasource. This is quick and dirty as it neglects session management but suits requirements.

Enhancing

This project will probably serve as a basis for other code. The best way to do this is to move it away from its original source and work with it.

###Tidy up list

  • Implement cleaner logging
  • Create unit tests
  • Add more CRUD actions in Hibernate

hibernate_quickstart's People

Contributors

blairdye avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.