论坛首页 Java企业应用论坛

Hibernate和Spring的决裂以及Spring和EJB3之争

浏览 36946 次
该帖已经被评为精华帖
作者 正文
   发表时间:2005-09-19  
Charlesxp 写道
引用
当然不错,但有没什么限制?

有!。你需要采用ejb3。 :-)


个人感觉这个东西Spring要实现起来本身不难,关键是Rod想不想这么做罢了。

有人觉得callback不好,有人觉得没啥问题,个人喜好罢了。
0 请登录后投票
   发表时间:2005-09-20  
Charlesxp 写道

没记错的话需要使用spring的transaction proxy。

你记错了

Charlesxp 写道

如果既可以不需要template,也不需要多谢try/catch,是不是更好?

spring又不是做ORM的,如果ORM native api就是扔出checked exception,你只能将它try/catch起来,这个和spring有啥关系?
0 请登录后投票
   发表时间:2005-09-20  
摘自spring reference 12.3.3 Implementing DAOs based on plain JDO API
引用
The main issue with such DAOs is that they always get a new PersistenceManager from the factory. To still access a Spring-managed transactional PersistenceManager, consider defining a TransactionAwarePersistenceManagerFactoryProxy (as included in Spring) in front of your target PersistenceManagerFactory, passing the proxy into your DAOs.

<beans>
  ...

  <bean id="myPmfProxy"
      class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
    <property name="targetPersistenceManagerFactory" ref="myPmf"/>
  </bean>


类似这样的限制在ejb3容器可以不需要。
0 请登录后投票
   发表时间:2005-10-10  
Readonly 写道

是的, 如果用H3.0.1以上版本的话,只用spring注入SessionFactory,然后改用getCurrentSession方法:
public class ProductDaoImpl implements ProductDao {
    private SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory); {
        this.sessionFactory = sessionFactory;
    }

    public Collection loadProductsByCategory(String category); {
        return this.sessionFactory.getCurrentSession();
                .createQuery("from test.Product product where product.category=?");
                .setParameter(0, category);
                .list();;
    }
}


在目前的spring版本里面, jdo/toplink/ibatis2/h3,都可以不用template方式,而改用各个orm的native api去做,唯一的区别就是:有些orm用的是checked exception,需要多写try/catch

这样的话,session是从orm这层直接获取的,那如何通过AOP的方式来控制事务?
0 请登录后投票
   发表时间:2005-10-10  
z_jordon 写道

这样的话,session是从orm这层直接获取的,那如何通过AOP的方式来控制事务?


看代码和文档啊,上面说得很明白了:
引用

The main advantage of this DAO style is that it depends on Hibernate API only; no import of any Spring class is required. This is of course appealing from a non-invasiveness perspective, and might feel more natural to Hibernate developers.

However, the DAO throws plain HibernateException (which is unchecked, so does not have to be declared or caught), which means that callers can only treat exceptions as generally fatal - unless they want to depend on Hibernate's own exception hierarchy. Catching specific causes such as an optimistic locking failure is not possible without tying the caller to the implementation strategy. This tradeoff might be acceptable to applications that are strongly Hibernate-based and/or do not need any special exception treatment.

A further disadvantage of that DAO style is that Hibernate's getCurrentSession() feature just works within JTA transactions. It does not work with any other transaction strategy out-of-the-box, in particular not with local Hibernate transactions.

Fortunately, Spring's LocalSessionFactoryBean supports Hibernate's SessionFactory.getCurrentSession() method for any Spring transaction strategy, returning the current Spring-managed transactional Session even with HibernateTransactionManager. Of course, the standard behavior of that method remains: returning the current Session associated with the ongoing JTA transaction, if any (no matter whether driven by Spring's JtaTransactionManager, by EJB CMT, or by plain JTA).

In summary: DAOs can be implemented based on plain Hibernate3 API, while still being able to participate in Spring-managed transactions. This might in particular appeal to people already familar with Hibernate, feeling more natural to them. However, such DAOs will throw plain HibernateException; conversion to Spring's DataAccessException would have to happen explicitly (if desired).
0 请登录后投票
   发表时间:2005-10-10  
看了Charlesxp的介绍,想试试JBoss的Embeddable EJB3.0
结果看到如下信息,不知道EJB3.0什么时候能成熟起来?一年?两年?
Charlesxp的产品何时能成熟?

引用
These are the limitations


We have only sparsely tested the embedded stack. Consider it an alpha release
The Embedded stack is based off of CVS HEAD, not JBoss 4.0.x. Future versions will be based off of 4.0.x code.
We have done no pruning of jar files so the distribution disc size is a little large.
Documentation is sparse. Hopefully the tutorial examples are enough to get started.
EJB/JBoss Security is not available yet.
XA Connection pool is not available yet.
When embedding into Tomcat, you still require a JBoss specific JNDI implementation. Tomcat's JNDI is read-only.
You still must use the JBoss transaction manager even when embedding in another app server vendor. This will be remedied in the future when the JBoss AOP/Microcontainer integration is complete.
Distributed remote communication is not supported yet.
EJB Timer service not supported
Even though @Remote interfaces are local, you can only communicate through local connections.
You cannot access JMS remotely. Only locally. Thus, you have to lookup the "java:/ConnectionFactory".
JNDI is not available remotely
0 请登录后投票
   发表时间:2005-10-11  
引用
Charlesxp的产品何时能成熟?

呵呵,太看得起我了。JBOSS挟数千万美元投资才做的个的embeded ejb3原型,区区个红工场,资金是零头的零头,人数也是零头的零头,jboss类型的嵌入式ejb3不是我们能做,也不是我们想做的。

由于有jdo实现为基础,实现EJB3 Persistence API不是一件很困难的事。使用ejb3 persistence api  + annotation是让人愉快的事。不用写类式hibernate/jdo那样的大堆的xml事让人轻松多了,而且运行测试超快(不用解析xml)。 但单单有ejb3 persisence api开发应用还不够好,我们本来期望spring能迅速支持ejb3 persistnece api并且是兼容ejb3 core api的方式支持,不是象原来的用个template(用template也不是不行,但就太浪费了ejb3规范中的injection了)。但种种原因显然这个日子会比较久。所以我们才决定开发一个很小的ejb3 container.她应该象spring那样管理对象,但又兼容ejb3 core api。至于其他事务,安全等ejb其它部分都依赖app server。由于我们不是app server厂商,我们更注重和各种不同app server的结合和在j2se中使用。

顺便说说TSS上关于JBOSS的business model的大讨论,不知不是人访问太多,那个blog我都无法访问。但从讨论中可以看到一个就是jboss的business model还是很具试验性质。而且服务价格不低。据我了解,jboss最基本的价格一个application, 1年1万美金(10万人民币),服务是8小时电子邮件响应,800电话。而国产的服务器的授权许可加一年的服务业不过这个价格,甚至更低。
0 请登录后投票
   发表时间:2005-10-11  
引用
扩大投资,增加开发人员数量...

I wish I could.但我也不可以让我老婆饿肚子咯。 VC喜欢投什么,大家也看得见。
0 请登录后投票
   发表时间:2005-10-12  
Charlesxp 写道
引用
扩大投资,增加开发人员数量...

I wish I could.但我也不可以让我老婆饿肚子咯。 VC喜欢投什么,大家也看得见。

可以利用开源的力量。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics