java - 数据库一条记录为什么经过hibernate查询变成一个对象了呢??
阿神
阿神 2017-04-18 10:56:07
0
5
807

今天面试问到了这个问题,他的意思是让剖析源码吗??突然感觉到好奇怪,,ORM框架,不就是这样的吗??求大神解释。谢了

阿神
阿神

闭关修行中......

reply all(5)
黄舟

I was too hasty to answer questions when I left the house in the morning. Now let’s talk about it in detail. Two points can be mentioned here:

  • Persistence

  • Deserialization

So PersistenceEveryone downstairs has mentioned that an object is saved to the storage system. In the case you mentioned, it is saved to the database. Then each attribute is generally used as a field, and then the value is saved as a record.

Then deserialization. The connection to the database is established through socket, so there is no doubt that it has gone through the network. If you need to transmit an object on the network, you must serialize it. In other words: The deserialization process has been completed when the ResultSet is obtained through the database link.

迷茫

So first use sql and see how to use the original jdbc, and you will know why there is this framework

PHPzhong

Generally, it is easier for interviewers to ask questionsJDBC就到底了吧,所以@泊浮目 所说的反序列化我觉得不是面试官的意思。用原生的JDBC执行SQL可以拿到ResultSet对象,框架不过是从里面取一个个字段值,然后封装到一个对象中而已。我的理解就是这样,也确实没看过这种ORM的源码,虽然我用Mybatis.

Peter_Zhu

This has nothing to do with deserialization.
The original JDBC query results in a ResultSet. Hibernate knows the correspondence between the fields and object properties in the ResultSet through xml configuration or Anotation, and then generates POJO objects through the reflection mechanism.

大家讲道理

What a coincidence. Sixteen hours after you posted the question, I was asked the same question in the interview.
My answer was basically the same as @Xing Aiming’s answer to this question. But looking at the reaction, I felt it was not what the interviewer wanted.
Personally, I think this kind of question is quite strange. The main reason is that I can’t get the specific aspect I want to assess.

There is another question. I checked several times to make sure I heard it correctly, but I still don’t understand what it is..
What is the difference between jquery ${} and #{}? Pay attention to the curly brackets..

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template