Bug 208375 - "restful web services from database" fails for composite PKs
"restful web services from database" fails for composite PKs
Status: RESOLVED FIXED
Product: webservices
Classification: Unclassified
Component: REST
7.1
PC Linux
: P3 (vote)
: TBD
Assigned To: Denis Anisimov
issues@webservices
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-02-14 09:32 UTC by kawazu428
Modified: 2012-10-11 02:01 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
USERDATA table structure (1.45 KB, application/octet-stream)
2012-02-16 08:47 UTC, kawazu428
Details
glassfish v3.1.1 server log (31.71 KB, text/x-log)
2012-02-16 08:47 UTC, kawazu428
Details
sample project structure, "as-is" without modifications (6.86 MB, application/x-compressed-tar)
2012-02-16 08:48 UTC, kawazu428
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kawazu428 2012-02-14 09:32:20 UTC
Used the 7.1 tooling to, in an existing maven project, try to create "RESTful web services from database". Selected a bunch of tables in our existing table schema, generated entities and @Stateless REST resources. Deploying the code to Glassfishv3, however, reproducibly fails the same way:


[...]
  SEVERE: Missing dependency for method public pvrest.db.Rolexauthority pvrest.service.RolexauthorityFacadeREST.find(pvrest.db.RolexauthorityPK) at parameter at index 0 
  SEVERE: Method, public pvrest.db.Rolexauthority pvrest.service.RolexauthorityFacadeREST.find(pvrest.db.RolexauthorityPK), annotated with GET of resource, class pvrest.service.RolexauthorityFacadeREST, is not recognized as valid resource method. 
  SEVERE: Missing dependency for method public void pvrest.service.RolexauthorityFacadeREST.remove(pvrest.db.RolexauthorityPK) at parameter at index 0 
  SEVERE: Method, public void pvrest.service.RolexauthorityFacadeREST.remove(pvrest.db.RolexauthorityPK), annotated with DELETE of resource, class pvrest.service.RolexauthorityFacadeREST, is not recognized as valid resource method.|#] 
[...]

Tried it a couple of times, including copying the facade+entity classes to an existing (working) Jersey+JPA project, with the same outcome, so it's basically reproducible. This message hits the server.log for each and every entity featuring a composite PK (which is kept in a dedicated <Entity>PK class).
Comment 1 Denis Anisimov 2012-02-16 08:08:04 UTC
This is a description of runtime problem.
I cannot identify the reason of this problem without IDE steps to reproduce.
It could be a runtime problem, JPA problem or any different kind of problem.
The REST is just an interface which is used to communicate with runtime application.
It is not obvious that the problem is REST NB support problem.
Please provide exact steps to reproduce.
Comment 2 kawazu428 2012-02-16 08:46:51 UTC
I disagree with the description of being a "runtime" problem as actually the only real IDE step involved is the one I outlined ("create restful web services from database"). However, in order to make things clear and also check with a different database backend to make sure it does not relate to JPA/JDBC issues with our production database:

- Used NetBeans 7.1. Created a plain Glassfishv3 installation by selecting a new folder and downloading/installing the bits. Started the server.

- Used the "jdbc/sample" Derby database connection to create a table USERDATA (attached grab). The structure is trivial, the table is empty, but it features a composite Primary Key.

- Created an empty maven project ("plain.tgz", also attached). 

- In there, chose "New" -> "RESTful Web Services From Database". Selected "jdbc/sample" as "Data Source", selected "USERDATA", added it to "Selected Tables". Stepped through all the steps to follow using Next/Finish without changing anything.

- Outcome: The IDE generated Userdata.java, UserdataPK.java, AbstractFacade.java and UserdataFacadeREST.java

- Right-clicked the project, chose "Run". In the output window, I watched the usual maven build stuff which works well, and then the output of the IDE trying to deploy this to the running Glassfishv3 domain.

- Deployment fails, the same way it did before. Attached the full server.log.
Comment 3 kawazu428 2012-02-16 08:47:17 UTC
Created attachment 115789 [details]
USERDATA table structure
Comment 4 kawazu428 2012-02-16 08:47:32 UTC
Created attachment 115790 [details]
glassfish v3.1.1 server log
Comment 5 kawazu428 2012-02-16 08:48:41 UTC
Created attachment 115791 [details]
sample project structure, "as-is" without modifications

This is the default project created by NetBeans IDE. Usually I would replace Jersey and JPA with artifacts off some repository.
Comment 6 kawazu428 2012-02-21 12:03:10 UTC
FWIW, just in case anyone else stumbles across this problem, too: A pretty straightforward workaround to this problem is to, in the *FacadeREST implementation, modify all methods that make use of the composite primary key, so from

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public MyPersistentEntity find(@PathParam("id") MyPersistentEntityPK id) {
        return super.find(id);
    }

to not make use of the *PK key class anymore but rather introduce one or more simple parameters and eventually use a custom query to find your entities this way. Regarding the REST/Jersey question however: Assuming "id" is supposed to be a path parameter, I wonder how deserializing from an URI path segment to a composite key entity actually would work, or, in this case, how the URI path segment representing {id} would have to look like to make this work.
Comment 7 Denis Anisimov 2012-04-09 11:36:53 UTC
Primary keys (to use them in the REST methods as param) should have 
types described at the @PathParam annotation javadoc:
http://jsr311.java.net/nonav/releases/1.0/javax/ws/rs/PathParam.html
PK in the example doesn't have required type. That's the issue.

To fix the issue one needs either PK modification or some wrapper class for PK 
to use it instead of PK in REST methods or deny REST service creation at all 
( in case of incompatible PK ).
Comment 8 Denis Anisimov 2012-10-10 10:10:23 UTC
web-main#130098a9af96
Comment 9 Quality Engineering 2012-10-11 02:01:02 UTC
Integrated into 'main-golden', will be available in build *201210110002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/130098a9af96
User: Denis Anisimov <ads@netbeans.org>
Log: Fix for BZ#208375 - "restful web services from database" fails for composite PKs


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo