Skip to main content



      Home
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 03:08 Go to next message
Eclipse UserFriend
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 #786491 is a reply to message #784225] Mon, 30 January 2012 08:52 Go to previous messageGo to next message
Eclipse UserFriend
I m still facing this problem, please help me in this regard
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #786498 is a reply to message #784225] Mon, 30 January 2012 08:52 Go to previous messageGo to next message
Eclipse UserFriend
I m still facing this problem, please help me in this regard
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #786579 is a reply to message #786498] Mon, 30 January 2012 10:53 Go to previous messageGo to next message
Eclipse UserFriend
Do not set,

aom.setIsPrimaryKeyMapping(true);

This is internal. Set the primary key fields using,

productTypeBuilder.setPrimaryKeyFields("field1", "field2", etc.).
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #786585 is a reply to message #786498] Mon, 30 January 2012 10:53 Go to previous messageGo to next message
Eclipse UserFriend
Do not set,

aom.setIsPrimaryKeyMapping(true);

This is internal. Set the primary key fields using,

productTypeBuilder.setPrimaryKeyFields("field1", "field2", etc.).
--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #787076 is a reply to message #786579] Tue, 31 January 2012 00:49 Go to previous messageGo to next message
Eclipse UserFriend
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 00:50 Go to previous messageGo to next message
Eclipse UserFriend
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 #787463 is a reply to message #787077] Tue, 31 January 2012 11:02 Go to previous messageGo to next message
Eclipse UserFriend
Any help regarding this issue?
I still didn't able to solve it.
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #787467 is a reply to message #787077] Tue, 31 January 2012 11:02 Go to previous messageGo to next message
Eclipse UserFriend
Any help regarding this issue?
I still didn't able to solve it.
Re: Composite Key Configuration using Dynamic Eclipse Link API [message #788759 is a reply to message #787463] Thu, 02 February 2012 02:16 Go to previous messageGo to next message
Eclipse UserFriend
I think there is a bug in org.eclipse.persistence.internal.jpa.CMP3Policy.java

Or may be i am missing something?

Please do help me in this regard, its been a week now that i m troubleshooting this problem.

Thank you

Re: Composite Key Configuration using Dynamic Eclipse Link API [message #789053 is a reply to message #788759] Thu, 02 February 2012 09:52 Go to previous messageGo to next message
Eclipse UserFriend
The same error i got with orm.xml.

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.1"
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<package>example.jpa.dynamic.model</package>
<entity class="Products" access="VIRTUAL">
<table name="Products"></table>
<attributes>
<embedded-id name="productKey" attribute-type="ProductKey"/>
<basic name="UnitPrice" attribute-type="java.lang.Double" />
<basic name="Discontinued" attribute-type="java.lang.Boolean" />
</attributes>
</entity>
<embeddable class="ProductKey" access="VIRTUAL">
<attributes>
<basic name="ProductID" attribute-type="java.lang.Integer" />
<basic name="ProductName" attribute-type="java.lang.String" />
</attributes>
</embeddable>
</entity-mappings>
---------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------
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 11:40 Go to previous message
Eclipse UserFriend
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.

Re: Composite Key Configuration using Dynamic Eclipse Link API [message #789136 is a reply to message #789053] Thu, 02 February 2012 11:40 Go to previous message
Eclipse UserFriend
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 : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:NoSQL
Next Topic:composite key order
Goto Forum:
  


Current Time: Tue Jul 15 12:49:17 EDT 2025

Powered by FUDForum. Page generated in 0.07333 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top