当前位置: 技术问答>java相关
J2EE design 的时候碰到的问题
来源: 互联网 发布时间:2015-11-17
本文导语: 如果一个数据库系统中的每一个表都能表示一类对象,是不是需要每个表都需要用一个CMP来表示出来,然后再将许多的CMP结合起来组成一个EJB哪? 举一个例子来说,如果要做一个飞机航线的entity bean ,里面必然涉...
如果一个数据库系统中的每一个表都能表示一类对象,是不是需要每个表都需要用一个CMP来表示出来,然后再将许多的CMP结合起来组成一个EJB哪?
举一个例子来说,如果要做一个飞机航线的entity bean ,里面必然涉及到机场,飞机种类等等,是不是机场,飞机都需要做成entity bean哪?
这样的话,会不会造成系统的ejb过度,使performance太差哪?
欢迎大家讨论
举一个例子来说,如果要做一个飞机航线的entity bean ,里面必然涉及到机场,飞机种类等等,是不是机场,飞机都需要做成entity bean哪?
这样的话,会不会造成系统的ejb过度,使performance太差哪?
欢迎大家讨论
|
For your example, you should do as you said. For the three classes/tables stand for three key parts in your applications. Consider another situation, if your plane has a proerty named 'manufactor' indicating which factory produced the plane. And cerntainly there is another table named like 'manufactors' shown below:
m_id int primary key
m_name varchar
and the relationship between table 'planes' and 'manufactors' is from the foreign key of 'planes' by 'p_manufactor' as shown below:
p_manufactor int references manufactors.m_id
How to deal with it if you think the manufactor is not so important in your application? Yes, do not wrap it as CMP, just make it a normal java class and access it through JDBC/SQL directly. So the CMP 'Plane' will have one property which is simply a int type for manufactor id. Or you can add one more helper property for the instance of class 'Manufactor', the normal class for the table 'manufactors', to let other objects access the Manufactor object but not the manufactor id directly.
m_id int primary key
m_name varchar
and the relationship between table 'planes' and 'manufactors' is from the foreign key of 'planes' by 'p_manufactor' as shown below:
p_manufactor int references manufactors.m_id
How to deal with it if you think the manufactor is not so important in your application? Yes, do not wrap it as CMP, just make it a normal java class and access it through JDBC/SQL directly. So the CMP 'Plane' will have one property which is simply a int type for manufactor id. Or you can add one more helper property for the instance of class 'Manufactor', the normal class for the table 'manufactors', to let other objects access the Manufactor object but not the manufactor id directly.