Hibernate is a persistence framework which is used to persist data from Java environment to database.
I am so confused, if we persist and object to a database, then why does Hibernate architecture indicate the persistent object in the middle of Application and Hibernate in picture?
我很困惑,如果我们坚持并反对数据库,那么为什么Hibernate架构会在Application和Hibernate中间指示持久对象?
6 个解决方案
#1
29
I will make it more clearer. Persistent objects are instances of POJO classes that you create that represent rows in the table in the database. According to hibernate-doc an instance of POJO class representing table in database goes through 3 states of which persistent is one of them.
我会让它更清晰。持久对象是您创建的POJO类的实例,它们表示数据库中表中的行。根据hibernate-doc,表示数据库中的表的POJO类的实例经历了3个状态,其中持久性是其中之一。
When a POJO instance is in session scope, it is said to be persistent i.e hibernate detects any changes made to that object and synchronizes it with database when we close or flush the session.
当POJO实例处于会话范围内时,它被认为是持久的,即当我们关闭或刷新会话时,hibernate会检测对该对象所做的任何更改并将其与数据库同步。
And about hibernate.properties and XML Mapping @Ken Chan is right. Go through hibernate-doc for more illustrations on objects in hibernate.
关于hibernate.properties和XML Mapping @Ken Chan是对的。通过hibernate-doc获取有关hibernate中对象的更多插图。
#2
15
Firstly you need to understand the three states of the Hibernate object i.e Transient, Persistent, Detached.
首先,您需要了解Hibernate对象的三种状态,即Transient,Persistent,Detached。
Transient state: An object is in transient state if it just has been instantiated using the new operator and there is no reference of it in the database i.e it does not represent any row in the database.
瞬态:如果对象刚刚使用new运算符进行实例化,并且数据库中没有对象的引用,则它处于临时状态,即它不代表数据库中的任何行。
Persistent state: An object is in the persistent state if it has some reference in the database i.e it represent some row in the database and identifier value is assigned to it. If any changes are made to the object then hibernate will detect those changes and effects will be there in the database that is why the name Persistent. These changes are made when session is closed. A persistent object is in the session scope.
持久状态:如果对象在数据库中有一些引用,则它处于持久状态,即它表示数据库中的某一行,并为其分配标识符值。如果对该对象进行了任何更改,那么hibernate将检测这些更改,并且数据库中将存在效果,这就是名称Persistent的原因。会话结束时会进行这些更改。持久对象在会话范围内。
Detached state: An object that has been persistent and is no longer in the session scope. The hibernate will not detect any changes made to this object. It can be connected to the session again to make it persistent again.
分离状态:持久且不再在会话范围内的对象。 hibernate不会检测对此对象所做的任何更改。它可以再次连接到会话以使其再次持久化。
#3
8
According to the figure , you configure hibernate.properties
or some XML mapping
to map a database table to a java object which is called persistent object
.
根据该图,您可以配置hibernate.properties或某些XML映射,以将数据库表映射到称为持久对象的java对象。
Then in your application
, you use the persistent object
as a normal java object to manipulate its state . You can pass persistent object
to hibernate .Hibernate will then generate and issue the necessary SQL to DB to synchronize the state of the persistent object
and its corresponding database record .Does it make sense ?
然后在您的应用程序中,使用持久对象作为普通的Java对象来操纵其状态。您可以将持久对象传递给hibernate。然后,Hibernate将生成并向DB发出必要的SQL,以同步持久对象的状态及其相应的数据库记录。这有意义吗?
#4
6
Persistent Objects are generally those objects that exist in memory even beyond the duration of the process that creates it. These objects are then stored in the database.
持久对象通常是存储在内存中的对象,甚至超出了创建它的进程的持续时间。然后将这些对象存储在数据库中。
#5
3
Persistent object is nothing but an instance of POJO class. And POJO class is nothing but a class that represents a table. And Hibernate always monitoring that persistent object. Whenever you manipulate that object or you made any changes in that object, Hibernate will do the same in that table (that one represent by the POJO class). that all handle by the hibernate. So in sort this is the one of the feature of hibernate framework.
持久对象只不过是POJO类的一个实例。而POJO类只不过是一个代表表的类。而Hibernate总是监视那个持久对象。无论何时操作该对象或者您在该对象中进行了任何更改,Hibernate都会在该表中执行相同的操作(该表由POJO类表示)。这一切都由hibernate处理。所以在排序中这是hibernate框架的一个特性。
#6
1
Persistant objects are the classes that in your program that has a representation in the database.
持久对象是程序中在数据库中具有表示的类。
Example if you have a Car class with the properties NumberPlate, Fuel. The NHibernate configuration will map this to for example a table in the database that is named Car and has these columns corresponding to the Car class properties.
例如,如果您的Car类具有NumberPlate,Fuel属性。 NHibernate配置将此映射到例如数据库中名为Car的表,并且这些列对应于Car类属性。
#1
29
I will make it more clearer. Persistent objects are instances of POJO classes that you create that represent rows in the table in the database. According to hibernate-doc an instance of POJO class representing table in database goes through 3 states of which persistent is one of them.
我会让它更清晰。持久对象是您创建的POJO类的实例,它们表示数据库中表中的行。根据hibernate-doc,表示数据库中的表的POJO类的实例经历了3个状态,其中持久性是其中之一。
When a POJO instance is in session scope, it is said to be persistent i.e hibernate detects any changes made to that object and synchronizes it with database when we close or flush the session.
当POJO实例处于会话范围内时,它被认为是持久的,即当我们关闭或刷新会话时,hibernate会检测对该对象所做的任何更改并将其与数据库同步。
And about hibernate.properties and XML Mapping @Ken Chan is right. Go through hibernate-doc for more illustrations on objects in hibernate.
关于hibernate.properties和XML Mapping @Ken Chan是对的。通过hibernate-doc获取有关hibernate中对象的更多插图。
#2
15
Firstly you need to understand the three states of the Hibernate object i.e Transient, Persistent, Detached.
首先,您需要了解Hibernate对象的三种状态,即Transient,Persistent,Detached。
Transient state: An object is in transient state if it just has been instantiated using the new operator and there is no reference of it in the database i.e it does not represent any row in the database.
瞬态:如果对象刚刚使用new运算符进行实例化,并且数据库中没有对象的引用,则它处于临时状态,即它不代表数据库中的任何行。
Persistent state: An object is in the persistent state if it has some reference in the database i.e it represent some row in the database and identifier value is assigned to it. If any changes are made to the object then hibernate will detect those changes and effects will be there in the database that is why the name Persistent. These changes are made when session is closed. A persistent object is in the session scope.
持久状态:如果对象在数据库中有一些引用,则它处于持久状态,即它表示数据库中的某一行,并为其分配标识符值。如果对该对象进行了任何更改,那么hibernate将检测这些更改,并且数据库中将存在效果,这就是名称Persistent的原因。会话结束时会进行这些更改。持久对象在会话范围内。
Detached state: An object that has been persistent and is no longer in the session scope. The hibernate will not detect any changes made to this object. It can be connected to the session again to make it persistent again.
分离状态:持久且不再在会话范围内的对象。 hibernate不会检测对此对象所做的任何更改。它可以再次连接到会话以使其再次持久化。
#3
8
According to the figure , you configure hibernate.properties
or some XML mapping
to map a database table to a java object which is called persistent object
.
根据该图,您可以配置hibernate.properties或某些XML映射,以将数据库表映射到称为持久对象的java对象。
Then in your application
, you use the persistent object
as a normal java object to manipulate its state . You can pass persistent object
to hibernate .Hibernate will then generate and issue the necessary SQL to DB to synchronize the state of the persistent object
and its corresponding database record .Does it make sense ?
然后在您的应用程序中,使用持久对象作为普通的Java对象来操纵其状态。您可以将持久对象传递给hibernate。然后,Hibernate将生成并向DB发出必要的SQL,以同步持久对象的状态及其相应的数据库记录。这有意义吗?
#4
6
Persistent Objects are generally those objects that exist in memory even beyond the duration of the process that creates it. These objects are then stored in the database.
持久对象通常是存储在内存中的对象,甚至超出了创建它的进程的持续时间。然后将这些对象存储在数据库中。
#5
3
Persistent object is nothing but an instance of POJO class. And POJO class is nothing but a class that represents a table. And Hibernate always monitoring that persistent object. Whenever you manipulate that object or you made any changes in that object, Hibernate will do the same in that table (that one represent by the POJO class). that all handle by the hibernate. So in sort this is the one of the feature of hibernate framework.
持久对象只不过是POJO类的一个实例。而POJO类只不过是一个代表表的类。而Hibernate总是监视那个持久对象。无论何时操作该对象或者您在该对象中进行了任何更改,Hibernate都会在该表中执行相同的操作(该表由POJO类表示)。这一切都由hibernate处理。所以在排序中这是hibernate框架的一个特性。
#6
1
Persistant objects are the classes that in your program that has a representation in the database.
持久对象是程序中在数据库中具有表示的类。
Example if you have a Car class with the properties NumberPlate, Fuel. The NHibernate configuration will map this to for example a table in the database that is named Car and has these columns corresponding to the Car class properties.
例如,如果您的Car类具有NumberPlate,Fuel属性。 NHibernate配置将此映射到例如数据库中名为Car的表,并且这些列对应于Car类属性。