OpenEJB 中的 CMP 实体 bean(OpenJPA?)
我尝试在 OpenEJB 上运行旧的 EJB2 系统,它使用 Entity Bean 来访问数据库。当前状态是我可以运行它并且可以将 SQL 发送到 Oracle DB(我可以在 Oracle 中看到会话和 SQL),但表和列名称未映射。
我认为原因是OpenEJB找不到表和列映射,我按照这篇文章配置
c:\openejb.xml:
<?xml version="1.0"?>
<openejb>
<Container id="Default CMP Container" ctype="CMP_ENTITY">
Global_TX_Database c:/cmp_global_database.xml
Local_TX_Database c:/cmp_local_database.xml
</Container>
</openejb>
cmp_global_database.xml:
<?xml version="1.0"?>
<database name="Global_TX_Database" engine="oracle">
<jndi name="java:comp/env/jdbc/oracle" />
<mapping href="c:/oracle.cmp_or_mapping.xml" />
</database>
cmp_local_database.xml:
<?xml version="1.0"?>
<database name="Local_TX_Database" engine="orcle">
<driver class-name="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@****:1521:****">
<param name="user" value="****"/>
<param name="password" value="****"/>
</driver>
<mapping href="C:\oracle.cmp_or_mapping.xml"/>
</database>
oracle.cmp_or_mapping.xml:
<?xml version="1.0"?>
<mapping>
<class name="com.***.***.***TblBean" identity="id" key-generator="SEQUENCE">
<map-to table="****_TBL"/>
<field name="id" type="integer" direct="true">
<sql name="id" type="integer"/>
</field>
<field name="firstname" type="string" direct="true">
<sql name="first_name" type="varchar" dirty="check"/>
</field>
<field name="lastname" type="string" direct="true">
<sql name="last_name" type="varchar" dirty="check"/>
</field>
<field name="email" type="string" direct="true">
<sql name="email" type="varchar" dirty="check"/>
</field>
</class>
</mapping>
这是日志
[DEBUG] jdbc.JDBC : SQL Cache missed with key: openejb.com.***.***TblBean in class org.apache.openjpa.jdbc.kernel.JDBCStoreManager
[DEBUG] jdbc.SQL : <t 11834440, conn 0> executing prepstmnt 14988216 SELECT t0.acceptDateTime, ... FROM ***TblBean t0 WHERE t0.id = ? [params=(String) ABC.1]
[DEBUG] jdbc.SQL : <t 11834440, conn 0> [0 ms] spent
[DEBUG] jdbc.JDBC : <t 11834440, conn 0> [0 ms] close
javax.ejb.ObjectNotFoundException: ***TblBean : ABC.1
at org.apache.openejb.core.cmp.CmpContainer.findByPrimaryKey(CmpContainer.java:661)
at org.apache.openejb.core.cmp.CmpContainer.invoke(CmpContainer.java:265)
at org.apache.openejb.core.entity.EntityEjbHomeHandler.findX(EntityEjbHomeHandler.java:63)
at org.apache.openejb.core.ivm.EjbHomeProxyHandler._invoke(EjbHomeProxyHandler.java:172)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:282)
I try to run an old EJB2 system on OpenEJB and it uses Entity Bean to access database. Current status is I can run it and can send SQL to Oracle DB (I can see the session and SQL in Oracle), but the table and column name is not mapped.
I think the reason is OpenEJB cannot find the table and column mapping, I followed this article to configure
c:\openejb.xml:
<?xml version="1.0"?>
<openejb>
<Container id="Default CMP Container" ctype="CMP_ENTITY">
Global_TX_Database c:/cmp_global_database.xml
Local_TX_Database c:/cmp_local_database.xml
</Container>
</openejb>
cmp_global_database.xml:
<?xml version="1.0"?>
<database name="Global_TX_Database" engine="oracle">
<jndi name="java:comp/env/jdbc/oracle" />
<mapping href="c:/oracle.cmp_or_mapping.xml" />
</database>
cmp_local_database.xml:
<?xml version="1.0"?>
<database name="Local_TX_Database" engine="orcle">
<driver class-name="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@****:1521:****">
<param name="user" value="****"/>
<param name="password" value="****"/>
</driver>
<mapping href="C:\oracle.cmp_or_mapping.xml"/>
</database>
oracle.cmp_or_mapping.xml:
<?xml version="1.0"?>
<mapping>
<class name="com.***.***.***TblBean" identity="id" key-generator="SEQUENCE">
<map-to table="****_TBL"/>
<field name="id" type="integer" direct="true">
<sql name="id" type="integer"/>
</field>
<field name="firstname" type="string" direct="true">
<sql name="first_name" type="varchar" dirty="check"/>
</field>
<field name="lastname" type="string" direct="true">
<sql name="last_name" type="varchar" dirty="check"/>
</field>
<field name="email" type="string" direct="true">
<sql name="email" type="varchar" dirty="check"/>
</field>
</class>
</mapping>
This is the log
[DEBUG] jdbc.JDBC : SQL Cache missed with key: openejb.com.***.***TblBean in class org.apache.openjpa.jdbc.kernel.JDBCStoreManager
[DEBUG] jdbc.SQL : <t 11834440, conn 0> executing prepstmnt 14988216 SELECT t0.acceptDateTime, ... FROM ***TblBean t0 WHERE t0.id = ? [params=(String) ABC.1]
[DEBUG] jdbc.SQL : <t 11834440, conn 0> [0 ms] spent
[DEBUG] jdbc.JDBC : <t 11834440, conn 0> [0 ms] close
javax.ejb.ObjectNotFoundException: ***TblBean : ABC.1
at org.apache.openejb.core.cmp.CmpContainer.findByPrimaryKey(CmpContainer.java:661)
at org.apache.openejb.core.cmp.CmpContainer.invoke(CmpContainer.java:265)
at org.apache.openejb.core.entity.EntityEjbHomeHandler.findX(EntityEjbHomeHandler.java:63)
at org.apache.openejb.core.ivm.EjbHomeProxyHandler._invoke(EjbHomeProxyHandler.java:172)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:282)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案,因为我发现一些新表是由JPA创建的(命名为***TblBean)。它使用Java对象的命名作为表名和列名。因为我们的数据库是 Oracle,所以我删除了 JPA 创建的表并创建了几个视图来映射到该表。现在可以了。
当然,我知道这不是一个好的解决方案,但至少有效。
I found a workaround solution, because I found some new tables are created by JPA (the naming is ***TblBean). It uses the naming of Java object to be the table and column name. And because our database is Oracle, I dropped the table created by JPA and created several views to map to the table. It works now.
Of course, I know it's not a good solution, but it works at least.