Hi there. Can someone give me a hint what's wrong running the castor sample? - In database.xml I entered driver and connection information for my Tamino SQL Engine. - In create.sql I adapted the SQL statements so my database will create the tables the way castor expects it. - In mapping.xml I actually tried not to change anything, but....
As Tamino SQL does not know about a numeric data type, I changed that to
float/decimal/whatever. From JDBC the data type is mentioned as DOUBLE.
However I keep getting the listed error message, and suspect that it occurs
with the price field. If it is the group_id, what can I do to overcome that
error?
Hiran
[test] Creating new product: <id: 4 name: product4>
[test] Castor: Creating myapp.Product (4)
[test] Error creating myapp.Product, SQL : INSERT INTO "prod"
("id","name","price","group_id") VALUES (?,?,?,?)
[test] org.exolab.castor.jdo.PersistenceException: Nested error:
java.sql.SQLException: setDouble() is wrong Method to set inputparameter 4
[test] java.sql.SQLException: setDouble() is wrong Method to set
inputparameter 4
[test] at
de.sag.jdbc.tsql.server.AInputServer.checkType(AInputServer.java:930)
[test] at
de.sag.jdbc.tsql.server.AInputServer.setDouble(AInputServer.java:345)
[test] at
de.sag.jdbc.tsql.server.AInputServer.setBigDecimal(AInputServer.java:351)
[test] at
de.sag.jdbc.tsql.server.AInputServer.setObject(AInputServer.java:723)
[test] at
de.sag.jdbc.tsql.APreparedStatement.setObject(APreparedStatement.java:665)
[test] at
de.sag.jdbc.tsql.APreparedStatement.setObject(APreparedStatement.java:674)
[test] at
org.exolab.castor.jdo.engine.SQLTypes.setObject(SQLTypes.java:420)
[test] at org.exolab.castor.jdo.engine.SQLEngine.create(SQLEngine.java:598)
[test] at
org.exolab.castor.persist.ClassMolder.create(ClassMolder.java:903)
[test] at org.exolab.castor.persist.LockEngine.create(LockEngine.java:458)
[test] at
org.exolab.castor.persist.TransactionContext.create(TransactionContext.java:
883)
[test] at
org.exolab.castor.jdo.engine.DatabaseImpl.create(DatabaseImpl.java:366)
[test] at castorjdo.Test.run(Test.java:222)
[test] at castorjdo.Test.main(Test.java:63)
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor JDO Configuration DTD Version 1.0//EN"
"http://castor.exolab.org/jdo-conf.dtd">
<!--
<database name="test" engine="mysql" >
<driver url="jdbc:mysql://localhost/castor_examples" class-name="org.gjt.mm.mysql.Driver">
<param name="user" value="test" />
<param name="password" value="test" />
</driver>
<mapping href="mapping.xml" />
</database>
-->
<!--
<database name="test" engine="postgresql" >
<driver class-name="org.postgresql.Driver" url="jdbc:postgresql://localhost/castor_examples">
<param name="user" value="test"/>
<param name="password" value="test" />
</driver>
<mapping href="mapping.xml" />
</database>
-->
<database name="test" engine="sapdb" >
<driver class-name="de.sag.jdbc.tsql.ADriver" url="jdbc:tsql:unicode://localhost:7200/CASTOR">
<param name="user" value="HCH"/>
<param name="password" value="HCH" />
</driver>
<mapping href="mapping.xml" />
</database>
create.sql
Description: Binary data
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>
<!-- Mapping for ProductGroup -->
<class name="myapp.ProductGroup" identity="id">
<description>Product group</description>
<map-to table="prod_group" xml="group" />
<field name="id" type="integer" >
<sql name="id" type="integer"/>
<bind-xml node="attribute"/>
</field>
<field name="name" type="string">
<sql name="name" type="char" dirty="check" />
<bind-xml node="text" />
</field>
</class>
<!-- Mapping for Product -->
<class name="myapp.Product" identity="id">
<description>Product definition</description>
<map-to table="prod" xml="product" />
<field name="id" type="integer">
<sql name="id" type="integer" />
<bind-xml name="id" node="attribute"/>
</field>
<field name="name" type="string">
<sql name="name" type="char" />
<bind-xml name="name" node="element" />
</field>
<field name="price" type="float">
<sql name="price" type="numeric" />
<bind-xml name="price" node="element" />
</field>
<!-- Product has reference to ProductGroup,
many products may reference same group -->
<field name="group" type="myapp.ProductGroup">
<sql name="group_id"/>
<bind-xml name="group" node="element" />
</field>
<!-- Product has reference to ProductDetail
many details per product -->
<field name="details" type="myapp.ProductDetail" required="true"
collection="vector">
<sql many-key="prod_id"/>
<bind-xml name="detail" node="element" />
</field>
<!-- Product has reference to Category with
many-many relationship -->
<field name="categories" type="myapp.Category" required="true"
collection="vector">
<sql name="category_id"
many-table="category_prod" many-key="prod_id" />
<bind-xml name="category" node="element" />
</field>
</class>
<!-- Mapping for Product Detail -->
<class name="myapp.ProductDetail" identity="id" depends="myapp.Product" >
<description>Product detail</description>
<map-to table="prod_detail" xml="detail" />
<field name="id" type="integer">
<sql name="id" type="integer"/>
<bind-xml node="attribute"/>
</field>
<field name="product" type="myapp.Product">
<sql name="prod_id" />
<bind-xml name="product" node="element" reference="true"/>
</field>
<field name="name" type="string">
<sql name="name" type="char"/>
<bind-xml node="text" />
</field>
</class>
<!-- Mapping for Computer, extending Product -->
<class name="myapp.Computer" extends="myapp.Product" identity="id">
<description>Computer definition, extends generic product</description>
<map-to table="computer" xml="computer" />
<field name="id" type="integer">
<sql name="id" type="integer" />
<bind-xml name="id" node="attribute"/>
</field>
<field name="cpu" type="string">
<sql name="cpu" type="char"/>
<bind-xml node="element" />
</field>
</class>
<!-- Mapping for Category -->
<class name="myapp.Category" identity="id">
<description>
A product category, any number of products can belong to
the same category, a product can belong to any number of
categories
</description>
<map-to table="category" xml="category" />
<field name="id" type="integer">
<sql name="id" type="integer"/>
<bind-xml/>
</field>
<field name="name" type="string">
<sql name="name" type="char"/>
<bind-xml node="element" />
</field>
<field name="products" type="myapp.Product" required="true"
collection="vector">
<sql name="prod_id"
many-table="category_prod" many-key="category_id" />
<bind-xml name="product" node="element" />
</field>
</class>
</mapping>
