Git Product home page Git Product logo

hibernate-mysql-crud's Introduction

hibernate-mysql-crud

A Simple Hibernate MySQL example explaining the CRUD operations

Load() - helps to load the data from database into the java object, it can be done in three way, pass the class, pass the entire package (entity name), pass the object of the Entity Object with id for all three cases ( for ex : load(Employee.class, empid))

Get() - same as that of load()… two ways… entity class, entity name(i.e full package) But the difference between these two is - > if the identifier does not exist in database”. In case of get() method you will get return value as NULL if identifier is absent; But in case of load() method, you will get a runtime exception Get() will hit the database all the time, load() will not hit the database

Refresh() - it's used to refresh the Entity Object with the latest values from the database

Merge() - used to merge the updated entity (detached Entity) Object into the database… ts merges the updated data with the entity in the memory before updating the database… errors like NonUniqueObjectException and "a different object with the same identifier value was already associated with the session" can be addressed if using merge… if you try to work on detached object without reattaching them and try to update() u will get the above error, in this case use merge

Save() - insert only

SaveOrUpdate() - both insert or update depending upon the data

Persist() - same as save() Difference between save and persist Save returns serializable object, persist does not return anything Save executes insert outside transaction boundary resulting in duplicate(when you use generated value), persist does not allow to execute outside transaction Save not good for long running conversations, persist good for long running conversation Persist is better to use than save

Delete() - used to delete the record

hibernate-mysql-crud's People

Contributors

gopikrishhnachokkalamani 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.