Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Help using the Dynamic JPA
Help using the Dynamic JPA [message #387427] Wed, 29 April 2009 03:43 Go to next message
Ajay Kumar is currently offline Ajay KumarFriend
Messages: 13
Registered: July 2009
Junior Member
Hello,
I am new to the Dynamic JPA. It is easy to create the tables in the simple
schema. However I am finding it difficult to find an example how to create
a two tables which are joined with each other.

Emp_Table -> having employee id
EmP_Relationship table -> have a emp_id which is foreign key to the
emp_table.

I want to create these tables using the dynamic JPA. so that I can run the
regular JPQL of inner/outer joing using these two tables.

Any help appreciated.

Thx
Ajay
Re: Help using the Dynamic JPA [message #387432 is a reply to message #387427] Wed, 29 April 2009 12:56 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Not sure what you mean by "Dynamic JPA"?

If you are using EclipseLink to create you database tables for you, then
to create a relationship you should have two objects with a OneToOne or
ManyToOne relationship between them.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: Help using the Dynamic JPA [message #387435 is a reply to message #387432] Wed, 29 April 2009 13:33 Go to previous messageGo to next message
Ajay Kumar is currently offline Ajay KumarFriend
Messages: 13
Registered: July 2009
Junior Member
I am using onetoonemapping relationship and that does not seem to work.
anotherMap.setAttributeName(fieldName); --> real field id for the table
anotherMap.addTargetForeignKeyFieldName(fieldName, fieldName);--> The
one to one relationship field id for the target and source field name
EntityProperty property = type.addProperty(anotherMap);

The part which seems to be missing is it has to get the name of the table
for which this table has relationship to.

How we indicate that? In absense of that, it does not create a join table.

Thx
Ajay
Re: Help using the Dynamic JPA [message #387441 is a reply to message #387435] Wed, 29 April 2009 23:52 Go to previous messageGo to next message
Ajay Kumar is currently offline Ajay KumarFriend
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
Re: Help using the Dynamic JPA [message #387766 is a reply to message #387441] Thu, 07 May 2009 19:02 Go to previous message
Doug Clarke is currently offline Doug ClarkeFriend
Messages: 155
Registered: July 2009
Senior Member
Ajay,

I have pre-occupied with other tasks and have not gotten back to working
on the dynamic persistence incubator. I am hoping to have some time
available next week as several folks have been asking for additional
functionality.

The incubator is tracked at

http://wiki.eclipse.org/EclipseLink/Development/JPA/Dynamic

and the bug is https://bugs.eclipse.org/bugs/show_bug.cgi?id=200045

If you have specific issues you want the solution to support please add
requirements to the bug and add yourself to the cc list of the bug. We
will update the bug with its progress as it is made. If you would like to
assist with enhancements to the incubator please let me know or attach
contributions to the bug.

Cheers,

Doug
Previous Topic:DDL generation with WriteTransformer
Next Topic:Getting NegativeArraySizeException: allocArray
Goto Forum:
  


Current Time: Tue Jan 14 14:32:23 GMT 2025

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

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

Back to the top