Sindhoo Oad
Sindhoo Oad

Reputation: 1194

what is persistence in hibernate?

I was reading out the basics of ORM from here where it is defined what is persistence?

here it is defined as

we would like the state of (some of) our objects to live beyond the scope of the JVM so that the same state is available later.

I could not understated what does it mean by beyond the scope of the JVM . what i have understood form this could be

Please correct me because truly speaking I did not understand this statement which is defined in Hibernates own official site.

Upvotes: 4

Views: 1074

Answers (3)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522752

beyond the scope of the JVM means that the state will still exist even after the JVM shuts down. Or, to put it another way, the existence of the state is not dependent on the existence of the JVM. Hibernate is an ORM (object relational mapping) tool which is typically used to map Java objects to records in a database somewhere. When used this way, Hibernate stores state from your Java program in one or more database tables.

Consider the following definition for the Person class:

public class Person {
    private String firstName;
    private String lastName;

    public Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    // getters and setters
}

Suppose you create 2 Person objects like this:

Person p1 = new Person("Jon", "Skeet");
Person p2 = new Person("Gordon", "Linoff");

If you were to persist these Person objects to the database using Hibernate, you might end up with a Person table looking like this:

+-----------+----------+
| firstName | lastName |
+-----------+----------+
| Jon       | Skeet    |
| Gordon    | Linoff   |
+-----------+----------+

If you stop your Java application and then start it up again, Hibernate can also work in the opposite direction to create Person objects from the rows in this database table.

Upvotes: 6

Oliver
Oliver

Reputation: 6260

Persistence means to save data in place that would remain or persist even after the power is turned off. For example saving data in text files is also persistence. Database is one of the ways of persisting data .

You know this, its just a big word.

Beyond the scope of JVM means the data should persist or be preserved even after JVM shuts down i.e your application shuts down.

Hibernate saves or persists a Java bean/object in database. So it is called ORM Object to Relational Mapping framework. This is simple they just use a lot of fancy words so it sounds cool.

Upvotes: 2

Kumar Saurabh
Kumar Saurabh

Reputation: 2305

it means the data get stored somewhere like a file or database even when your application is closed so that next time u can use the data again

Upvotes: 1

Related Questions