Home » Eclipse Projects » EclipseLink » Composite Key Configuration using Dynamic Eclipse Link API
Composite Key Configuration using Dynamic Eclipse Link API [message #784225] |
Fri, 27 January 2012 08:08 |
Nabeel Ahmed Messages: 20 Registered: January 2012 |
Junior Member |
|
|
I m try to configure a Dynamic Type which have composite primary key, but i am having a problem in its configuration.
/*
* Configuring ProductKey
*/
JPADynamicTypeBuilder productKeyTypeBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(packageName + "ProductKey"), null);
productKeyTypeBuilder.addDirectMapping("ProductID", int.class,"ProductID");
productKeyTypeBuilder.addDirectMapping("ProductName", String.class, "ProductName");
/*
* Configuring Products
*/
JPADynamicTypeBuilder productTypeBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(packageName + "Products"), null, "Products");
productTypeBuilder.addDirectMapping("QuantityPerUnit", String.class,"QuantityPerUnit");
productTypeBuilder.addDirectMapping("UnitPrice", Double.class, "UnitPrice");
productTypeBuilder.addDirectMapping("UnitsInStock", Short.class, "UnitsInStock");
productTypeBuilder.addDirectMapping("UnitsOnOrder", Short.class, "UnitsOnOrder");
productTypeBuilder.addDirectMapping("ReorderLevel", Short.class, "ReorderLevel");
productTypeBuilder.addDirectMapping("Discontinued", Boolean.class, "Discontinued");
AggregateObjectMapping aom = productTypeBuilder.addAggregateObjectMapping("ProductKey", productKeyTypeBuilder.getType(), true);
aom.setIsPrimaryKeyMapping(true);
aom.setIsReadOnly(false);
and i m getting errors in it.
am i missing anything?
any help?
|
|
| | | | |
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #787076 is a reply to message #786579] |
Tue, 31 January 2012 05:49 |
Nabeel Ahmed Messages: 20 Registered: January 2012 |
Junior Member |
|
|
Thanks for your reply, i tried it.
/*
* Configuring ProductKey
*/
JPADynamicTypeBuilder productKeyTypeBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(
packageName + "ProductKey"), null, "Products");
productKeyTypeBuilder.addDirectMapping("ProductID", int.class,"ProductID");
productKeyTypeBuilder.addDirectMapping("ProductName", String.class, "ProductName");
/*
* Configuring Products
*/
JPADynamicTypeBuilder productTypeBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(
packageName + "Products"), null,"Products");
productTypeBuilder.setPrimaryKeyFields("ProductID", "ProductName");
productTypeBuilder.addAggregateObjectMapping("productKey", productKeyTypeBuilder.getType(), true);
productTypeBuilder.addDirectMapping("QuantityPerUnit", String.class, "QuantityPerUnit");
productTypeBuilder.addDirectMapping("UnitPrice", Double.class, "UnitPrice");
productTypeBuilder.addDirectMapping("UnitsInStock", Short.class, "UnitsInStock");
productTypeBuilder.addDirectMapping("UnitsOnOrder", Short.class, "UnitsOnOrder");
productTypeBuilder.addDirectMapping("ReorderLevel", Short.class, "ReorderLevel");
productTypeBuilder.addDirectMapping("Discontinued", Boolean.class, "Discontinued");
when i run the code on JBoss AS 7.1.0 with SQL Server 2010, Now i got this error.
is it a bug in EclipseLink 2.3.2?
if not, then what is missing/wrong here?
------------
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: An internal error occurred accessing the primary key object [202].
Internal Exception: java.lang.NoSuchFieldException: ProductID
Descriptor: RelationalDescriptor(com.lgc.dsl.model.Products --> [DatabaseTable(Products)])
|
|
|
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #787077 is a reply to message #786579] |
Tue, 31 January 2012 05:50 |
Nabeel Ahmed Messages: 20 Registered: January 2012 |
Junior Member |
|
|
Thanks for your reply, i tried it.
/*
* Configuring ProductKey
*/
JPADynamicTypeBuilder productKeyTypeBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(
packageName + "ProductKey"), null, "Products");
productKeyTypeBuilder.addDirectMapping("ProductID", int.class,"ProductID");
productKeyTypeBuilder.addDirectMapping("ProductName", String.class, "ProductName");
/*
* Configuring Products
*/
JPADynamicTypeBuilder productTypeBuilder = new JPADynamicTypeBuilder(classLoader.createDynamicClass(
packageName + "Products"), null,"Products");
productTypeBuilder.setPrimaryKeyFields("ProductID", "ProductName");
productTypeBuilder.addAggregateObjectMapping("productKey", productKeyTypeBuilder.getType(), true);
productTypeBuilder.addDirectMapping("QuantityPerUnit", String.class, "QuantityPerUnit");
productTypeBuilder.addDirectMapping("UnitPrice", Double.class, "UnitPrice");
productTypeBuilder.addDirectMapping("UnitsInStock", Short.class, "UnitsInStock");
productTypeBuilder.addDirectMapping("UnitsOnOrder", Short.class, "UnitsOnOrder");
productTypeBuilder.addDirectMapping("ReorderLevel", Short.class, "ReorderLevel");
productTypeBuilder.addDirectMapping("Discontinued", Boolean.class, "Discontinued");
when i run the code on JBoss AS 7.1.0 with SQL Server 2010, Now i got this error.
is it a bug in EclipseLink 2.3.2?
if not, then what is missing/wrong here?
------------
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: An internal error occurred accessing the primary key object [202].
Internal Exception: java.lang.NoSuchFieldException: ProductID
Descriptor: RelationalDescriptor(com.lgc.dsl.model.Products --> [DatabaseTable(Products)])
|
|
| | | | |
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #789135 is a reply to message #789053] |
Thu, 02 February 2012 16:40 |
|
I think the issue is you are trying to use an embedded id, with a class that does not exist. Don't do this, just define each id (no different than if it was a singleton pk).
The full stack trace would help diagnose the issue with using an embedded id, my guess is there is an issue there that you may wish to log bug for.
You should be able to use a List or Object[] of the id values if using find.
Otherwise you could try defining a real class for the id.
James : Wiki : Book : Blog : Twitter
|
|
| |
Goto Forum:
Current Time: Fri Sep 20 06:54:17 GMT 2024
Powered by FUDForum. Page generated in 0.07183 seconds
|