对于CMP的一些问题

我刚刚开始学习EJB,在看完一些资料以后,有一些疑问,如果谁有用CMP做过实际项目请帮忙解答一下,先谢了.

1.composite primary key:
如果一个EJB的主键是单一的简单对象,用CMP实现是比较方便,但是实际上有时候很多数据库的结构都已经是固定的,你必须使用2个或者多个field来作为对应的主键定义,那么就必须得写自己的primary key class吗? 是否有其他简单的方法可以解决?

2.find method:
CMP用EJB-QL来实现查找,但是从文档上看EJB-QL好像只支持单个类EJB的查找,是否有什么办法可以实现多个EJB的查找?我在一些文档上看到说可以用CMP的relationship来实现,但是都没有详细的例子,请帮忙介绍一些有详细example的资料,谢谢!

3.分页显示:
从CMP的实现原理上看,为了实现对于不同的数据库的支持,所以没有办法写出类似于select limit 5,10这样的特殊的数据库语句,那么如果要做分页的话,有什么变通方法?

我还想问一下用过CMP做实际应用项目的感受,想了解一下它的技术风险,因为给我的感觉还不够成熟,谢谢!

To answer you questions
1> In strict EJB CMP, you need to declare a key class for every Entity Bean. don't worry, advanced EJB design tool like WSAD will generate it for you automatically.
2> in EJB2.0 you can't, that's why both weblogic and websphere has their proprietory extension in current product. EJB2.1 introduce dynamic EJB SQL, but you have to wait
3> Fetch in block is a very broad topic, we should fork a seperate thread for that. To answer you question straightly, you can't relay on SQL today, nor recommended in future. On positive side, most CMP has smart incremental fetch.

CMP is future, I see it making process every year, all of its regulations are tool friendly, but not human friendly, so find a better tool is important, unfortunately none of them exist for the time being. I can guranttee your failure if you apply them on large project today.
Best bet today is having your own "CMP": means seperate your business logic with persistent logic, handle later one by your own framework or one of many existing products such as expresso, castor etc.


Regards
-Wanchun

谢谢Jevang的回答,这样看来CMP真的还不适合做project. :(

另外对于第3点有不同意见,Quote:"you can't relay on SQL today":

我们应该发挥各种database的特性,针对不同的db写一些不同的实现定位的sql语言,比如Oracle用rownum,Mysql用Limit等等.还有不同的db的实现automatic key的方式也不一样,我们还是得写不同的sql.除非等到这些都成为标准sql的一部分,我们程序员才能舒服一点,we have to relay on SQL today, because performance is important in most projects.

Hi wys,
I was not clear or precise about my comment about using DB dependent SQL: I mean don't try to use them within CMP.
Idealy it's the job of container to automatically generate DB dependent sql for best performance, to my knowledge, some persistence engines such as Websphere5, toplink already can take advantage of native db features to handle locking, auto number outer join etc. You make some declaration regardless of underlying db.
When can we see all the nice features becomes generic across allCMP, don't know, just think about how long it took SUN to add LOB and auto number handling APIs into JDBC.