I am having difficulty retrieving all the Zipcode, Zipname records which have successfully been deployed on Glassfish v2r2, JDK1.6.0_06, MySQL 5.0, Netbeans 6.1 on Windows XP platform.
Below are the relevant EJBs snippets:
( i ) As a result, please advice on how to utilise both fetchZipcodesWithRelationships() & fetchZipnamesWithRelationships() in ZipcodeApplicationClient() to retrieve collections of Zipcodes & Zipnames without encountering this issue? (ii) I also like to utilise the zipnamebean.createZipnamez(zipname_1) to properly create this entity.
The local firewall has been de-activated. All components reside on the same host.
I have tried various approaches and googled without success.
I have updated createQuery statement as you have rightly pointed out to use "SELECT zc FROM Zipcode zc LEFT JOIN FETCH zc.zipnames" yet the outcomes is back to where we started with (ie. without the need to use createQuery with LEFT JOIN FETCH).
The remainder of ZipcodeApplicationClient() that retrieves all the records using fetch with relationship are as follows:
This is a step forward as it no longer throws an exception.
I would like to use the fetchZipnamesWithRelationships() within fetchZipcodesWithRelationships(), only if it is necessary despite having used the FETCH JOIN Query in fetchZipcodesWithRelationships() already.
OK, I am still confused, as I am not seeing the problem here.
But this is what I am taking from it
You have a client, who is connecting to a server in a different JVM. On the client you create these POJO objects, then you have Remote EJBs being called. On the Remote EJB, you have coupled your business logic and your Data Access object with EJB3 and your Stateless Session Bean. My first recommendation would be to decouple that code. Create a DAO class that uses the EntityManager to do the querying and CRUD.
Anyway, besides that point.
So the client creates this object, outside of an EntityManager, you send it to the server, and expect the server side EntityManager to persist it. Well that object is not being managed by the EntityManager at that point, it is considered the detached state. You will need to merge() the detached object into the EntityManager to allow it to manage it and then therefore after, persist it.
I have by-passed the use of these ZipcodeBean and ZipnameBean with the following simplified ZipcodeApplicationClient. This will eliminate the possibility of referencing detached Zipcode or Zipname objects:
However, another type of deployment error message is produced:
Initial deploying GeographicalBean to C:\Documents and Settings\Jack\GeographicalBean\dist\gfdeploy Completed initial distribution of GeographicalBean Start registering the project's server resources Finished registering server resources moduleID=GeographicalBean deployment started : 0% deployment finished : 100% Deploying application in domain completed successfully Trying to create reference for application in target server completed successfully Trying to start application in target server completed successfully WARNING: JDO76614: Deployment encountered SQL Exceptions: JDO76609: Got SQLException executing statement "CREATE TABLE ZIPCODE (ID INTEGER NOT NULL, DIALING_CODE VARCHAR(255), TIME_ZONE VARCHAR(255), CODE INTEGER, NEAREST_AIRPORT VARCHAR(255), LONGITUDE VARCHAR(255), NEAREST_TRAIN_STATION VARCHAR(255), NEAREST_URBAN_CENTRE VARCHAR(255), HOTELS VARCHAR(255), LATITUDE VARCHAR(255), NEARBY_FEATURES VARCHAR(255), COUNCIL VARCHAR(255), LOCALITY VARCHAR(255), PRIMARY KEY (ID))": com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'zipcode' already exists JDO76609: Got SQLException executing statement "CREATE TABLE ZIPNAME (ID INTEGER NOT NULL, NAME VARCHAR(255), ZIPCODE_ID INTEGER, PRIMARY KEY (ID))": com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'zipname' already exists JDO76609: Got SQLException executing statement "ALTER TABLE ZIPNAME ADD CONSTRAINT FK_ZIPNAME_ZIPCODE_ID FOREIGN KEY (ZIPCODE_ID) REFERENCES ZIPCODE (ID)": com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Key column 'ZIPCODE_ID' doesn't exist in tableEnable of GeographicalBean in target server completed successfully Enable of application in all targets completed successfully All operations completed successfully post-run-deploy: run-deploy: run-display-browser: run-ac: Copying 1 file to C:\Documents and Settings\Jack\GeographicalBean\dist Caught an unexpected exception! java.lang.NullPointerException at client.ZipcodeApplicationClient.main(ZipcodeApplicationClient.java:58) 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 com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266) at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449) at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259) at com.sun.enterprise.appclient.Main.main(Main.java:200) run-GeographicalBean-app-client: run:
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
a bit of art, as a gift, the permaculture playing cards