日期:2014-05-17  浏览次数:20808 次

这是什么事儿呀!看看这几道题就知道百度和谷歌的不同之处了!
这几道题是我考软件资格师认证见到的最无语的题了!那位要是能做出来的话说明你MVC和STRUTS学的不错!

1、在三层结构中,数据访问层承担的责任是( )。
(A) 定义实体类
(B) 数据的增删改查操作
(C) 业务逻辑的描述
(D) 页面展示和控制转发
 这个题百度选B谷歌选C,你们看看选啥呀!

2、在持久化层,对象分为哪些状态?( )
  (A) 瞬时(Transient)
(B) 脱管(Detached)
(C) 新建(New)
(D) 持久(Persistent)
 这个题我都想哭这百度选C谷歌选ACD!

3、、对于以下程序,Customer对象在第几行变为持久化状态?( )
  Customer customer=new Customer();  
  customer.setName("Tom");  
  Session session1=sessionFactory.openSession();  
  Transaction tx1 = session1.beginTransaction(); //line1
  session1.save(customer); //line2
  tx1.commit(); //line3
 session1.close(); //line4
  (A) line4
(B) line1
(C) line3
(D) line2
  这个百度选A谷歌选D,哎!无语!

4、、Spring的配置文件中数据源的常用类是( )?
  (A) LocalSessionFactoryBean
(B) BasicDataSource
(C) BasicDataSourceFactory
(D) DataSourceFactory
这个也是百度选B谷歌选D!
5、根据下面的Struts2的Action配置,哪一个url是访问该Action中的register方法?
  <action name=”reg” class=”action.UserAction”></action>
  (A) reg.action!register
(B) register!reg.action
(C) reg.action
(D) reg!register.action
 这个题百度没有!谷歌觉得选D!
以上题我个人做的答案是1、C 2、C 3、D 4、B 5、C
希望大家帮忙斧正!

------解决方案--------------------
1、在三层结构中,数据访问层承担的责任是( )。
(A) 定义实体类
(B) 数据的增删改查操作
(C) 业务逻辑的描述
(D) 页面展示和控制转发

首先,三层架构并不是MVC架构,先把这个问题确认好。

然后三层架构一般定义是:表现层(UI)、业务逻辑层(BLL)、数据访问层(DAL)。

那么结论其实很清晰:选项C的职责,必然是业务逻辑层(有的称服务层)负责的。
------解决方案--------------------
2、在持久化层,对象分为哪些状态?( )
(A) 瞬时(Transient)
(B) 脱管(Detached)
(C) 新建(New)
(D) 持久(Persistent)

这个东西来自于Hibernate,并非业界通用。

所以很简单,直接看Hibernate的官方文档即可:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html

Transient - an object is transient if it has just been instantiated using the new operator, and it is not associated with a Hibernate Session. It has no persistent representation in the database and no identifier value has been assigned. Transient instances will be destroyed by the garbage collector if the application does not hold a reference anymore. Use the Hibernate Session to make an object persistent (and let Hibernate take care of the SQL statements that need to be executed for this transition).

Persistent - a persistent instance has a representation in the database and an identifier value. It might just have been saved or loaded, however, it is by definition in the scope of a Session. Hibernate will detect any changes made to an object in persistent state and synchronize the state with the database when the unit of work completes. Developers do not execute manual UPDATE statements, or DELETE statements when an object should be made transient.

Detached - a detached instance is an object that has been persistent, but its Session has been closed. The reference to the object is still valid, of course, and the detached instance might even be modified in this state. A detached instance can be reattached to a new Session at a later point in time, making it (and all the modifications) persistent again. This feature enables a programming model for long running units of work that require user think-time. We call them application transactions, i.e., a unit of work from the point of view of the user.

还有疑虑乎?
------解决方案--------------------
3、、对于以下程序,Customer对象在第几行变为持久化状态?( )
Customer customer=new Customer();
customer.setName("Tom");
Session session1=sessionFactory.openSession();
Transaction tx1 = session1.beginTransaction(); //line1
session1.save(customer);