[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] Re: Help using the Dynamic JPA

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(loader);

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.nullPointerWhileGettingValueThruInstanceVariableAccessor(DescriptorException.java:1232)
at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:87)
at org.eclipse.persistence.extension.dynamic.EntityProperty$DynamicAttributeAccessor.getAttributeValueFromObject(EntityProperty.java:221)
at org.eclipse.persistence.mappings.DatabaseMapping.getAttributeValueFromObject(DatabaseMapping.java:429)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.getAttributeValueFromObject(ForeignReferenceMapping.java:531)
at org.eclipse.persistence.extension.dynamic.EntityProperty.getRawFromEntity(EntityProperty.java:100)
at org.eclipse.persistence.extension.dynamic.EntityProperty.putInEntity(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(EclipseLinkJPATest.java:246)
at testing.EclipseLinkJPATest.populate(EclipseLinkJPATest.java:219)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.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(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.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(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.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.InstanceVariableAttributeAccessor.getAttributeValueFromObject(InstanceVariableAttributeAccessor.java:75)
... 29 more