I am İshak Teyran , the data manager of a team which attends to IBM XML Challenge Turkey , we are trying to build a dynamic web project in Rational Software Architect 7.5, WAS 7.0 , DB2 9.5 EE.
the article of Vitor Rodrigues - http://www.ibm.com/developerworks/da...ues/index.html - describes how to map xml to java using pureQuery however we need to do the same using JPA.. is there any difference?
we are trying to achieve the same using JPA. but unfortunately we failed..
for simplifying lets assume we have two tables , STUDENT ( id int, name char) and COURSES ( studentID int , and lessons xml) ... these two tables are related to each other with studentID foreign key... and we want to have student and courses java files where courses.java includes proper mapping to xml column lessons..
i tried to make an .xsd file for xml column lessons.. and then i created its java file.. then i used JPA for creating student and courses java files but it always turns me a null pointer exception.. i dont know why.. and as result , only student.java is being created..
i have tried following steps.
My database connection and the tables are already present.
1- i have created a new dynamic web site project, namely dene..
from project facets i enabled dynamic web module, faces support (base, enhanced componnents) , Java Persistence, Javascript Toolkit, JavaServer faces, JSTL, Web 2.0 , Websphere Web(Co-existence),Websphere Web(Extended),Default Style Sheet facets.. and these facets musts be enabled for our project.
2- i have created the CourseList.xsd and using -JAXB- i have created lessons.java
3- i right clicked project and from the menu .. JPA tools->Generate Entities .. i choose connection and tables to generate entities but unfortunately no entity gets created ... when i only choose student table to generate the entity of, Student.java is being created however Courses.java always returns nullpointerexception..
the stack trace of the exception is in the picture i attached.. here is its link.. http://www.ibm.com/developerworks/fo...36353/hata.JPG
i have thought it might be because i use the openjpa and jaxb libraries of RSA.. and then i tried to load the latest versions of JAXB and openjpa .. i added all of their .jar files to the application classpath.. (if it is sufficient to add only openjpa-1.2.0.jar and jaxb-api.jar files let me know it please).. but this did not work neither..
the only exception i get is :
An internal error occurred during: "Generating Entities".
java.lang.NullPointerException
while creating lessons.java and the entity java files i am making sure that i give the same package name for both ... but i never succeeded creating courses.java..
in RSA when i right click to project and go te JPA Tools menu there is a menu item "Configure Project for JDBC deployment" .. what is this for.. i have also tried using this and then trying to create entities but this failed too..
then when they did not work ;
i have decided to code the classes myself but in order to get things a little easier, i opened my DB and converted the XML column to a SMALLINT column .. just not an XML column... and then using JPA in RSA - i did not include openJPA jars in my project externally- i created the classes .. both Course.java and Student.java have been created well, because the column that was actually xml was converted to small integer..
and if i add the related persistence and strategy lines :
@Persistent
@Strategy("org.apache.openjpa.xmlmapping.XmlValueH andler")
to their proper places and editing the function and attributes data types and return types and then if i re-convert the column to XML data type in database, do you think it will work properly?
so i really need a suggestion.. any help will be appreciated..
what would you suggest?
how can we achieve this goal for those two tables i mentioned above in RSA and using JPA ?