You really do understand java serialization

Q: But I have this entity class does not implement the serialization interface can also be saved to the database, which is why?

I can not figure out! I am using annotations and hibernate framework get!

Do not say implement the serialization interface is also able to save data? It should not be ah.

@Entity
public class Person {

@Id @GeneratedValue
private Integer id;
private String name;
private Integer age;
}

A: You use habernate save the data, as long as the XML file is configured, the entity class DAO layer all right, call the SAVE method then COMMIT you can save the data.

Serialization mainly you want to keep the data, converted into bytecode form of anti-serialization is turned into bytecode data.

You directly to the data submitted to the hard disk via the local server, you do not need serialization.

But you would not be in the transmission network, when you pass someone a thing, it receives all the bytecode after, you do not know what the object was originally passed, I could not get this thing to resolve in accordance with the original .

After you sequence and, in the other pass, when he received serialization will follow a specific pattern, to deserialize out, which means you pass something, but also what the other to receive, parse, you can use the method correctly and property.

Follow-up: You do not know what I mean, I'm not asking what is called serialization
I ask you, I did not realize serial interfaces Serializable

Why you can also save objects to the database?

A chase: originally be saved ah. When you think about most database and start learning JAVA, we write directly to class, write preservation method, and then connect to the database, save the data, then the object properties, there is no serialization is not directly saved it.

Abstract entity class is just a table only. Of course you can save ah.

Data already saved and serialization does not matter. . .

Connect to the database, call the save method, no exceptions directly to, and then close the connection, whether you use hibernate or was, or SSH framework, is a reason. Data submitted data only when there is no abnormal things happened, the success JAVA, simulated according to the corresponding table field stored in the table. It serialization, nothing to do.

Follow-up: that is saved only entity class field of each attribute to the database. Serialization is not required
and there are no objects involved, the operation between the database and the entity classes implements Serializable not be
saved in the database that is not an object to! But only numeric data

A chase: you this is a good question, actually I have already said that. . .

Save itself only to save the data, but you have serialized, it is in accordance with certain standards, ways to save.

Follow-up: Now see, I simply save the data and save objects confuse
it is not so to understand
such simple data: Hello
to save the object: Hello Joe Smith (assuming that Joe Smith is an object)
that is saving objects is more than an object + all the property field
and simply save the data, that is, only to save all property fields

A chase: This statement is not quite correct. It called for objects, in other words can not be achieved. . . Originally saved is the data.

What an object is? It is dispensed to a memory address area, which has the heap and stack. . They were used to record the object, class, attribute these things. But it is only a temporary storage space, you think, ah, memory space zoning. Right.

Objects can not be saved, saved only objects in the corresponding data fields, because the entity class itself is abstract table fields only.

Serialization you remember, is simply a way to save pattern data. . With it, the network transmission security, but also hundred percent resolution.

Follow-up: ah, that object can not save it, but you can simulate record this right, such as not to have a sequence of uid Oh, that
that sign is not on behalf of the object, as you said objects can not save, but I can own generating an id tag,
so that all the fields and attributes can be returned into the tag below, and then transmitted through the network to the other side. There after receipt of
contrast id tag, found to be the same, and then began to recover all the attributes of a successful transmission of stored objects!

Chase A: Your table has an identity column on the right, XML document hibernate configuration already on the identity column and the corresponding entity class field identifies the column are handled ah, you certainly saved the corresponding Yeah.

As for what was saved, I should be wrong, really saved the object. Specifically the field object is stored in the package, but said the book is to preserve the objects. .

Follow-up: you are mistaken I am not talking about a corresponding database identifies
me is to preserve the identity of the object
after you should know that implement the Serializable interface, there is not a thing uid
plus you just said object is just a temporary memory address, you can not save is not it
so we create a uid own identity the object, the object is not able to save the thing
I am asking the uid is not what it means, do not say something now in the database, the object is the transmission

A chase: This I really can not answer you.
Serialization of a class, the following tips do not appear yellow, I point it directly, and then came out of the uid, and the corresponding value, what specific role, this is not clear.

Follow-up: It seems more to the bottom of the more esoteric. But I feel it should be is and you said that the target can not save a relationship. Do you want an object can not save, that rely on to identify the object, there must be a mark, right? Thus jvm automatically based on a hash value produced uid, go to the other side through the transmission network, the other side after receiving the uid, and local objects will uid contrast, it does not match, it will update the data object is deserialized. Updated version of the software are so get, as long as the changes do not demonstrate the same uid, uid not the same, as evidenced by a new version that can be updated

A chase: Halo Yeah, I do not feel so deeply chase it, in fact, to this level is not we learn a.

Every time it updates or, where any minor changes are in line with SUN-designed system, the entire architecture is JAVA

We, as a programmer, do not have to see something so deep it!

But the other hand, this UID, maybe your guess is right, it may be corrected in this way, be regarded as a process of elimination it.

If the article helpful, please remember to focus on points like yo ~
Welcome to my public concern number <Love it>, pushing daily technical articles for them to learn.

Guess you like

Origin www.cnblogs.com/zhixie/p/11776355.html