JBossCMP2 Bug - Generated insert stmt incorrect
twhphan Feb 3, 2002 3:14 AMHaving problem with JBoss 3 generated insert stmt, not sure why it generates "INSERT INTO ViewShortcut (username, line, resourcesProperties, url, username) VALUES (?, ?, ?, ?, ?)" when I execute:
Collection c = viewSettingLocal.getViewShortcuts();
c.add(getViewShortcutLocalHome().create(username, line, resourcesProperties, url));
Note: it thinks that the table has two username columns
---
Error:
[Default] 2446400 [RMI TCP Connection(22)-] DEBUG org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.ViewShortcut ViewFacade ViewShortcut - Executing SQL: SELECT COUNT(*) FROM ViewShortcut WHERE username=? AND line=?
...
[Default] 2446412 [RMI TCP Connection(22)-] DEBUG org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.ViewShortcut ViewFacade ViewShortcut - Executing SQL: INSERT INTO ViewShortcut (username, line, resourcesProperties, url, username) VALUES (?, ?, ?, ?, ?)
...
[ViewShortcut] Could not create entity
java.sql.SQLException: General error: Column 'username' specified twice
---
Background info:
ViewSetting is the parent, and ViewShortcut is the child
ViewSetting.username is the primary key for the parent table
ViewShortcut.username and ViewShortcut.line for the child table
ViewShortcut.username is the foreign key
---
ejb-jar.xml
<![CDATA[No Description.]]>
<ejb-name>ViewSetting</ejb-name>
<local-home>esb.interfaces.ViewSettingLocalHome</local-home>
esb.interfaces.ViewSettingLocal
<ejb-class>esb.ejb.ViewSettingCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>ViewSetting</abstract-schema-name>
<cmp-field>
<![CDATA[]]>
<field-name>username</field-name>
</cmp-field>
...
<primkey-field>username</primkey-field>
<![CDATA[No Description.]]>
<ejb-name>ViewShortcut</ejb-name>
<local-home>esb.interfaces.ViewShortcutLocalHome</local-home>
esb.interfaces.ViewShortcutLocal
<ejb-class>esb.ejb.ViewShortcutCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>esb.interfaces.ViewShortcutPK</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>ViewShortcut</abstract-schema-name>
<cmp-field>
<![CDATA[]]>
<field-name>username</field-name>
</cmp-field>
<cmp-field>
<![CDATA[]]>
<field-name>line</field-name>
</cmp-field>
<cmp-field>
<![CDATA[]]>
<field-name>resourcesProperties</field-name>
</cmp-field>
<cmp-field>
<![CDATA[]]>
<field-name>url</field-name>
</cmp-field>
<ejb-relation>
<ejb-relation-name>setting-shortcut</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>one-setting-has-many-shortcuts</ejb-relationship-role-name>
One
<relationship-role-source>
<ejb-name>ViewSetting</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>viewShortcuts</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>one-shortcut-belongs-to-one-setting</ejb-relationship-role-name>
Many
<relationship-role-source>
<ejb-name>ViewShortcut</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
---
jbosscmp-jdbc.xml:
<ejb-name>ViewShortcut</ejb-name>
<table-name>ViewShortcut</table-name>
<create-table>true</create-table>
<remove-table>false</remove-table>
<tuned-updates>true</tuned-updates>
<read-only>false</read-only>
<time-out>100</time-out>
<cmp-field>
<field-name>line</field-name>
<column-name>line</column-name>
</cmp-field>
<cmp-field>
<field-name>resourcesProperties</field-name>
<column-name>resourcesProperties</column-name>
</cmp-field>
<cmp-field>
<field-name>url</field-name>
<column-name>url</column-name>
</cmp-field>
<cmp-field>
<field-name>username</field-name>
<column-name>username</column-name>
</cmp-field>
<ejb-relation>
<ejb-relation-name>setting-shortcut</ejb-relation-name>
<foreign-key-mapping>
<ejb-relationship-role>
<ejb-relationship-role-name>one-setting-has-many-shortcuts</ejb-relationship-role-name>
<foreign-key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>one-shortcut-belongs-to-one-setting</ejb-relationship-role-name>
<fk-constraint>false</fk-constraint>
<foreign-key-fields>
<foreign-key-field>
<field-name>username</field-name>
<column-name>username</column-name>
</foreign-key-field>
</foreign-key-fields>
</ejb-relationship-role>
</foreign-key-mapping>
</ejb-relation>
---
The extra username field may be created after JBoss reads <foreign-key-field/> in the jbosscmp-jdbc.xml
Is this a JBoss bug or I misunderstand something?
Thanks