对接口的深刻理解

时间:2021-10-06 23:40:17
 [main] DEBUG org.springframework.context.support.FileSystemXmlApplicationContext - Publishing event in org.springframework.context.support.FileSystemXmlApplicationContext@35960f05: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.FileSystemXmlApplicationContext@35960f05: startup date [Tue Oct 07 01:19:29 CST 2014]; root of context hierarchy]
[main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'CustomerDAO'
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Creating new transaction with name [dao.daoImpl.CustomerDAO.save]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Opened new Session [org.hibernate.impl.SessionImpl@e56c3cf] for Hibernate transaction
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@e56c3cf]
[main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Bound value [org.springframework.orm.hibernate3.SessionHolder@47875da7] for key [org.hibernate.impl.SessionFactoryImpl@3b5ad1da] to thread [main]
[main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Initializing transaction synchronization
[main] DEBUG org.springframework.transaction.interceptor.TransactionInterceptor - Getting transaction for [dao.daoImpl.CustomerDAO.save]
[main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@47875da7] for key [org.hibernate.impl.SessionFactoryImpl@3b5ad1da] bound to thread [main]
[main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@47875da7] for key [org.hibernate.impl.SessionFactoryImpl@3b5ad1da] bound to thread [main]
[main] DEBUG org.springframework.orm.hibernate3.HibernateTemplate - Found thread-bound Session for HibernateTemplate
Hibernate: select max(customer_id) from customer
[main] DEBUG org.springframework.orm.hibernate3.HibernateTemplate - Not closing pre-bound Hibernate Session after HibernateTemplate
[main] DEBUG org.springframework.transaction.interceptor.TransactionInterceptor - Completing transaction for [dao.daoImpl.CustomerDAO.save]
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCommit synchronization
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCompletion synchronization
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction commit
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@e56c3cf]
Hibernate: insert into test.customer (cname, password, sex, Born_date, school, subject, Origin_address, class, cellphone, email, photo, certificate, Student_id, Nick_name, Hunt_state, Work_limit, mydate, customer_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering afterCommit synchronization
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering afterCompletion synchronization
[main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Clearing transaction synchronization
[main] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Removed value [org.springframework.orm.hibernate3.SessionHolder@47875da7] for key [org.hibernate.impl.SessionFactoryImpl@3b5ad1da] from thread [main]
[main] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Closing Hibernate Session [org.hibernate.impl.SessionImpl@e56c3cf] after transaction
[main] DEBUG org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
save ok


大半夜,收获就是对接口的另一大必要作用又有了深入理解
查了一个晚上“为什么SRPING+HIBERNATE进行SQL插入时成功,数据库没有成功”
明明知道很可能是事务没有提交,可是还想找其他原因
最终还是说服自己试试提交事务,但是发现如果提交事务用到了代理
一旦用到了代理spring上下文ac.getBean()得到的就不是纯粹的POJO了而一个sun.proxy.$Proxy11
一看又是动态代理
强制转化不了啊····
纠结了半天··该怎么办
悟出的结论:接口是所有类的【外表】。。。父类是所有类的【内在】
【代理】托管了【父类】,但是【外表】是不会变的

所有可以把【代理】的【接口】强制性“暴露”(强制性转化)出来

    ApplicationContext ac = new FileSystemXmlApplicationContext("src/applicationContext.xml");
       
    customerDao=(customerDaoImpl)ac.getBean("CustomerDAO");
完成任务@