开发者

CMP entity bean in OpenEJB (OpenJPA?)

开发者 https://www.devze.com 2023-04-12 23:44 出处:网络
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 t

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

http://www.jarvana.com/jarvana/view/openejb/openejb/0.9.2/openejb-0.9.2.zip!/%5Bdot%5D/openejb-0.9.2/docs/cmp_entity_postgresql.html

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>开发者_JAVA百科
</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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号