|
Hello!
In all probability I might be doing something wrong, but could somebody
please point out to me where and what I'm doing wrong?
I have four entities: Product, Attribute, Store and Category.
A Product has many Attributes. A Store has one Product. A Product belongs
to many Categories. A Category belongs to many Products.
I get a LockNotGrantedException when I store a Product graph. When I store
a Product I'm storing all "Related Objects" explicitly. Only Attribute is a
"Dependent Object" on Product which I'm not storing explicitly. This exception
occurs AFTER the first Category is created inside the for loop which creates all
Categories for the new Product.
Thanks for any/all help.
Ayush
I get the following exception:
******************************************************************************
Exception I'm
getting:
[ERROR,Default]
org.exolab.castor.jdo.LockNotGrantedException: Lock is already existed for the
new oid.
----
----
----
----
[INFO,Default] Nested error: Key Generator Failure.
Duplicated Identity is generated!
[ERROR,Default] org.exolab.castor.jdo.PersistenceException: Nested error: Key Generator Failure. Duplicated Identity is generated! ******************************************************************************
Environment
Stateless Session Beans in Jboss 2.4.4
MS Sql Server 7
Using Identity Keygenerator for all tables ******************************************************************************
Client Code:
Product p = new
Product();
p.productName = "Crank Shaft"; p.descr = "Cranking the shaft in the 6 gauge engine"; Category c1 = new
Category();
c1.categoryName = "Engine Parts"; p.categories.add(c1); c1.products.add(p); Category c2 = new Category(); c2.categoryName = "Crank Internals"; p.categories.add(c2); c2.products.add(p); Attribute a1 = new
Attribute();
a1.attributeName = "cylinders"; a1.attributeValue = "6"; p.attributes.add(a1); a1.product = p; Attribute a2 = new Attribute(); a2.attributeName = "manufacturer"; a2.attributeValue = "Audi"; p.attributes.add(a2); a2.product = p; p.store = new
Store();
p.store.storeName = "Jennings Auto Parts"; p.store.city = "Los Angeles"; castorTest.addProduct(p);
******************************************************************************
Stateless Session Bean which makes JDO
Calls:
Database db = ((DataObjects) (new
InitialContext()).lookup("java:jdo/someName")).getDatabase();
for(int i=0; i<
((ArrayList)newProduct.categories).size();
i++)
db.create((Category)((ArrayList)newProduct.categories).get(i)); db.create(newProduct.store); db.create(newProduct); db.close();
System.out.println("closed!"); ****************************************************************************** mapping.xml
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" "D:/castor-0.9.3.9/schema/mapping.dtd"> <mapping> <class name="jdo.castor.value.Product"
key-generator="IDENTITY" identity="productId">
<map-to table="Product" /> <field name="productId" type="integer" direct="true"> <sql name="productId" type="integer" /> </field> <field name="productName" type="string" direct="true"> <sql name="productName" type="varchar" /> </field> <field name="descr" type="string" direct="true"> <sql name="descr" type="varchar" /> </field> <field name="categories"
type="jdo.castor.value.Category" collection="collection"
direct="true">
<sql name="categoryId" many-table="ProductCategory" many-key="productId" /> </field> <field name="attributes" type="jdo.castor.value.Attribute" collection="collection" direct="true"> <sql many-key="productId" /> </field> <field name="store" type="jdo.castor.value.Store" direct="true"> <sql many-key="storeId" /> </field> </class> <class name="jdo.castor.value.Category"
key-generator="IDENTITY" identity="categoryId">
<map-to table="Category" /> <field name="categoryId" type="integer" direct="true"> <sql name="categoryId" type="integer" /> </field> <field name="categoryName" type="string" direct="true"> <sql name="categoryName" type="varchar" /> </field> <field name="products" type="jdo.castor.value.Product" collection="collection" direct="true"> <sql name="productId" many-table="ProductCategory" many-key="categoryId" /> </field> </class> <class name="jdo.castor.value.Attribute"
key-generator="IDENTITY" identity="attributeId"
depends="jdo.castor.value.Product" >
<map-to table="Attribute" /> <field name="attributeId" type="integer" direct="true"> <sql name="attributeId" type="integer" /> </field> <field name="attributeName" type="string" direct="true"> <sql name="attributeName" type="varchar" /> </field> <field name="attributeValue" type="string" direct="true"> <sql name="attributeValue" type="varchar" /> </field> <field name="product" type="jdo.castor.value.Product" direct="true"> <sql name="productId" /> </field> </class> <class name="jdo.castor.value.Store"
key-generator="IDENTITY" identity="storeId">
<map-to table="Store" /> <field name="storeId" type="integer" direct="true"> <sql name="storeId" type="integer" /> </field> <field name="storeName" type="string" direct="true"> <sql name="storeName" type="varchar" /> </field> <field name="city" type="string" direct="true"> <sql name="city" type="varchar" /> </field> </class> </mapping>
******************************************************************************
|
- [castor-dev] Key Generator Failure Ayush Gupta
- [castor-dev] Key Generator Failure Arun Sudhakaran
- Re: [castor-dev] Key Generator Failure Claude Vedovini
