|
|
|
Re: Help using the Dynamic JPA [message #387441 is a reply to message #387435] |
Wed, 29 April 2009 23:52 |
Ajay Kumar Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Let me give some more insight into this. I have following problems while
creating the joined tables.
I have the following scheme for the joined table with the Employee (which
is part of the example)
The following creates a table which is DYNAMIC_EMP_RELATION and it is
linked with Employee table.
-----------------
Loading entity--->
DynamicClassLoader loader = new DynamicClassLoader(null,
DynamicEntity.class);
session.getPlatform().getConversionManager().setLoader(loade r);
employeeRelationship = EntityTypeFactory.create("EmployeeRelationShip",
"model.EmployeeRelationShip", "DYNAMIC_EMP_RELATION", loader);
EntityTypeFactory.addBasicProperty(employeeRelationship, "id", "EMP_ID",
Integer.class, true);
EntityTypeFactory.addBasicProperty(employeeRelationship, "relation",
"RELATION",
String.class, false);
Class entityClass = null;
entityClass = loader.loadClass("model.Employee");
EntityTypeFactory.addJoinProperty(employeeRelationship,
"EMP_ID","Employee",entityClass);
EntityTypeFactory.addToSession((Server) session, employeeRelationship);
-------------------------
After this I create the relationship table
// Drop and create the table
new SchemaManager(JpaHelper.getServerSession(emf))
.replaceDefaultTables();
---------------
One thing I noticed is that there is no foreign key relationship while
creting DYNAMIC_EMP_RELATION. I hope to see a foreign key relationship on
the database schema level. It creates the schema with no foreign key.
My question is if I am missing something here? Any help?
Another part is that I use the "Loading entity" code given above to
insert/get the data. I have following problems
using the following query to get the result
------
List resultSet = em
.createQuery(
"SELECT e FROM EmployeeRelationShip e")
.getResultList();
------
com.sun.jdi.InvocationException occurred invoking method. Any ideas here,
what I am doign wrong?
While inserting the data I have the following problem.
here is the way I am inserting the values
DynamicEntity emp = empType.newInstance();
emp.set("id", 1);
emp.set("relation", "Bob");
em.persist(emp);
Any idea what I am doing wrong?
Local Exception Stack:
Exception [EclipseLink-69] (Eclipse Persistence Services - 1.0.2 (Build
20081024)): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException was thrown while extracting
a value from the instance variable [id] in the object
[model.EmployeeRelationShip].
Internal Exception: java.lang.NullPointerException
at
org.eclipse.persistence.exceptions.DescriptorException.nullP ointerWhileGettingValueThruInstanceVariableAccessor(Descript orException.java:1232)
at
org.eclipse.persistence.internal.descriptors.InstanceVariabl eAttributeAccessor.getAttributeValueFromObject(InstanceVaria bleAttributeAccessor.java:87)
at
org.eclipse.persistence.extension.dynamic.EntityProperty$Dyn amicAttributeAccessor.getAttributeValueFromObject(EntityProp erty.java:221)
at
org.eclipse.persistence.mappings.DatabaseMapping.getAttribut eValueFromObject(DatabaseMapping.java:429)
at
org.eclipse.persistence.mappings.ForeignReferenceMapping.get AttributeValueFromObject(ForeignReferenceMapping.java:531)
at
org.eclipse.persistence.extension.dynamic.EntityProperty.get RawFromEntity(EntityProperty.java:100)
at
org.eclipse.persistence.extension.dynamic.EntityProperty.put InEntity(EntityProperty.java:78)
at
org.eclipse.persistence.extension.dynamic.DynamicEntity.set( DynamicEntity.java:53)
at
org.eclipse.persistence.extension.dynamic.DynamicEntity.set( DynamicEntity.java:49)
at
testing.EclipseLinkJPATest.populateRelationShip(EclipseLinkJ PATest.java:246)
at testing.EclipseLinkJPATest.populate(EclipseLinkJPATest.java: 219)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod (BeforeAndAfterRunner.java:74)
at
org.junit.internal.runners.BeforeAndAfterRunner.runBefores(B eforeAndAfterRunner.java:50)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:33)
at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMe thodRunner.java:75)
at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRu nner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTest Method(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestCl assMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected( TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected (BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunn er.java:52)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.r un(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(Test Execution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
Caused by: java.lang.NullPointerException
at
org.eclipse.persistence.internal.descriptors.InstanceVariabl eAttributeAccessor.getAttributeValueFromObject(InstanceVaria bleAttributeAccessor.java:75)
... 29 more
|
|
|
|
Powered by
FUDForum. Page generated in 0.12796 seconds