Loading Tabel Descriptor and Class Descriptor XML's ??? - TopLink/JPA

Hi All,
Is there a way of loading table descriptor and class descriptor xmls using Toplink API???.
if C:\Model is the folder where .mwp project file is saved, table descriptor xmls are those under C:\Model\Table folder and class descriptor xmls are those under c:\Model\Descriptor folder.
regards.
Erdem. 

You must generate the "deployment" XML from the Mapping Workbench to read it in the runtime TopLink API. You cannot load the Mapping Workbench development XML directly in the TopLink runtime.
For the tables you can generate a "Table Creator class" from the Mapping Workbench to be able to access and create you're tables at runtime.

Related

How can I specify table owners when I export project to Java source?

Using TopLink Mapping Workbench, when I export project to Java source, the descriptors is automatically generated like:
descriptor.addTableName("SOME_TABLE");
Is there a way to configure the TopLink Mapping Workbench so it generates the descriptors so that the table owner is explicitly specified?
descriptor.addTableName("SCHEMA_A.SOME_TABLE");
Thanks! 
You can re-name your tables in the MW to be fully qualified for the name and that's how it will be generated and used.
Doug 
Thanks, that worked wonderfully!

Query the mapping

Is it possible to query TopLink which classes and which members are mapped? Or how can I know programatically whether a class or a field has already been mapped? 
You can access the mapping metadata from the session. The model is basically:
session.project.descriptor.mapping
To most common way to lookup a descriptor for a mapped class in 10.1.3 is:
   session.getClassDescriptor(MyClass.class);Doug

TopLink-JAXB : Creating and Mapping tables from Toplink-JAXB POJOs.

Hi All,
I'm new to toplink and I need a help specific to TopLink-JAXB.
I've an XML Schema, imported it in toplink and generated the POJOs corresponding to the XSD. Also it generates the "O-X" descriptors. Now I want to map these classes to tables in Oracle database. How can I do so..? Do we have any specific ways of converting a "O-X" descriptior to a "Relational" descriptor"..? Or how these generated POJOs can be mapped to tables in database..?
Can any one please help me in this regard
Thanks
Raj 
Hello Raj,
There are a couple different approaches that you can take:
1. Generate the model using JAXB and then map objects to relational tables
This is the specific approach that you have asked about. There isn't an automatic way to convert an OXM project to an ORM project. Instead you will need to create a new TopLink ORM project in the TopLink Workbench, then import the generated JAXB model classes and table information and create TopLink mappings.
For more information on using TopLink JAXB:
http://www.oracle.com/technology/products/ias/toplink/technical/tips/jaxb/index.htm
For more information on mapping existing Java classes to a Relational Database:
http://www.oracle.com/technology/products/ias/toplink/doc/10131/main/_tutorial/index.htm
2. Use the TopLink Workbench to generate objects from a database schema and then map objects to an XML Schema
Similar to the first approach except that the database schema is used to generate the object model. This can be done by creating a new Relational TopLink Workbench project and loading the database schema information. Then right click on a Table and choose the "Generate Classes and Descriptors from" option. Now you can create a TopLink OXM project and map these generated classes to an existing XML Schema.
For more information on mapping existing Java classes to an XML schema:
http://www.oracle.com/technology/products/ias/toplink/technical/tips/ox/index.htm
3. Design your own object model and use TopLink to map it to both your relational database and XML schemas
This is my preferred option since you can design an object model true to your domain. Object models generated from a database or XML schemas tend to show a bias towards what they were generated from. The advantage of using TopLink is that it can map any object model to any database or XML schema
-Blaise 
Hi Blaise,
Thanks for a prompt response.Now, I'm tying to import the XSD into toplink and I get the following exception..
Can you guide me where the problem is..?
oracle.toplink.ox.jaxb.compiler.TopLinkJAXBGenerationException: java.lang.Exception: collision in cl
ass name mapping at node "{0}".
at oracle.toplink.ox.jaxb.compiler.tljaxb.invokeOrajaxb(tljaxb.java:244)
at oracle.toplink.ox.jaxb.compiler.tljaxb.generate(tljaxb.java:78)
at oracle.toplink.ox.jaxb.compiler.tljaxb.main(tljaxb.java:48)
Caused by: java.lang.Exception: collision in class name mapping at node "{0}".
at oracle.xml.jaxb.JaxbSchemaCompiler.putBindingSchema(JaxbSchemaCompiler.java:3239)
at oracle.xml.jaxb.JaxbSchemaCompiler.putBindingSchema(JaxbSchemaCompiler.java:3221)
at oracle.xml.jaxb.JaxbSchemaCompiler.compileSchema(JaxbSchemaCompiler.java:595)
at oracle.xml.jaxb.JaxbSchemaCompiler.compile(JaxbSchemaCompiler.java:403)
at oracle.toplink.ox.jaxb.compiler.tljaxb.invokeOrajaxb(tljaxb.java:221)
... 2 more
java.lang.Exception: collision in class name mapping at node "{0}".
at oracle.xml.jaxb.JaxbSchemaCompiler.putBindingSchema(JaxbSchemaCompiler.java:3239)
at oracle.xml.jaxb.JaxbSchemaCompiler.putBindingSchema(JaxbSchemaCompiler.java:3221)
at oracle.xml.jaxb.JaxbSchemaCompiler.compileSchema(JaxbSchemaCompiler.java:595)
at oracle.xml.jaxb.JaxbSchemaCompiler.compile(JaxbSchemaCompiler.java:403)
at oracle.toplink.ox.jaxb.compiler.tljaxb.invokeOrajaxb(tljaxb.java:221)
at oracle.toplink.ox.jaxb.compiler.tljaxb.generate(tljaxb.java:78)
at oracle.toplink.ox.jaxb.compiler.tljaxb.main(tljaxb.java:48)
Thanks
Raajasekaran
rajasekaran.iyanu#oracle.com 
Hello Raajasekaran,
In JAXB classes are generated for both Elements and Complex Types. In some instances this causes two classes to be generated with the same name. To get around this problem you need inform the JAXB compiler that one of the classes should be given another name. This can be done by annotation the XML Schema. I have included an example below:
<xs:complexType name="foo">
<xs:annotation>
   <xs:appinfo>
     <jaxb:class name="MyClassName" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"/>
   </xs:appinfo>
</xs:annotation>
...
</xs:complexType>-Blaise 
For more information on JAXB customizations check out:
http://java.sun.com/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html
-Blaise

Descriptor Mapping

I have a master descriptor java file for my project that contains the descriptors for all the tables in my database.
Is it possible to generate a visual representation without connecting to the Database ?
Since all the mapping relations are there in the descriptor file rather than the tables and there are nearly 70 tables in the database and corresponding descriptors that provides the mapping between the java objects and the table , is there any way to generate a visual representation of the relationships with the help of available master descriptor file? . It is an exacting task if had to go descriptor by descriptor.
Please advise and help me out .

Toplink with XML as storage

I am trying to use XML as storage for Toplink. The example given uses the project class file to establish session, where as in the mapping workbench, i do not see any option to generate the project java source for a XML type of project. There is only option to generate the project deployment XML, using which i am not able to establish a session for the XML storage.
i am using Toplink 10.0.3 Developer preview. Is it like this version doesn't have support for the generation of project java source for XML type of project? Does 9.0.4 version has support for it? If anybody has any idea kindly update me.
Thanks in Advance 
The TopLink 10.0.3 developer preview offers new support for object to XML mapping. Currently their is only support in the Mapping Workbench for generating deployment XML. Below is a snippet of code for loading a project from deployment XML.
import oracle.toplink.sessions.Project;
import oracle.toplink.tools.workbench.XMLProjectReader;
import oracle.toplink.ox.XMLMarshaller;
...
XMLProjectReader projectReader = new XMLProjectReader();
Project project = projectReader.read("MyProject.xml");
XMLMarshaller marshaller = new XMLMarshaller(project); 
Many thanks for the sugegstion. I tried creating the session from Delpoymet XML file as per your suggestion, but i do get the following error.
Exception Description: The aggregate object [class CLASS1] cannot be directly registered in the UnitOfWork. It must be associated with the source (owner) object.
My code is as below.
XMLProjectReader projectReader = new XMLProjectReader();
Project project = projectReader.read("trial.xml");
XMLMarshaller marshaller = new XMLMarshaller(project);
dbSession = marshaller.getSession();
XMLFileLogin filelogin = new XMLFileLogin();
filelogin.setBaseDirectoryName("C:\\toplink\\Demos\\xml");
filelogin.createDirectoriesAsNeeded();
dbSession.setDatasourceLogin(filelogin);
dbSession.login();
dbSession.initializeIdentityMaps();
UnitOfWork uow = dbSession.acquireUnitOfWork();
CLASS1 object1 = new CLASS1();
CLASS1 object = (CLASS1)uow.registerObject(object1);
object.setName("REPR01");
object.setID("ABC-123");
object.setTS(Calendar.getInstance());
object.setAnotherID("123");
uow.commit();
I have a complex type XSD mapped to the class attributes using the direct to field mapping for all attributes. But the <toplink:descriptor-type> in the generated Deployment file shows the value as "aggregate". i think this is what is causing the problem.
Does anybody faced this situation before. Any suggestions are highly appreciated.
thanks in advance 
The are two parts to the new object-to-XML support that has been added to TopLink in 10.0.3.
The first is a data conversion layer, which developers can use to convert an XML document to/from objects. This is done using the XMLMarshaller class. The XMLMarshaller contains marshal and unmarshal methods similar to JAXB, also TopLink 10.0.3 provides a JAXB runtime which can be used instead of XMLMarshaller to perform data conversions. Since this data conversion is non-transactional, it is not meant to be used with a session. The getSession() method is meant to only be used internally by TopLink. XML projects created in the Mapping Workbench can only be used with the data conversion layer.
The second part is a persistence layer. The persistence layer is used when TopLink is used to access a data store. In terms of the new object-to-XML support a J2C project is created and the objects are mapped to XML schemas that represent the structure of XML interactions that will executed against a J2C compliant adapter. The persistence layer is normally used in a transactional enviroment and TopLink sessions (including UnitOfWork) are used. Customers familar with using TopLink to access a relational database will find using TopLink to access a legacy data store exposed with a J2C adapter is very similar since the data store specifics are captured during the mapping phase.
As part of the TopLink SDK a mechanism has been offered that allows objects to be persisted to a directory of XML files. This mechanism (which can be found in oracle.toplink.xml package, while the new object-to-xml support can be found in the oracle.toplink.ox package) is not compatible with the new object-to-xml support offered in the Mapping Workbench for 10.0.3.

Categories

Resources