This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | "restful web services from database" fails for composite PKs | ||
---|---|---|---|
Product: | webservices | Reporter: | kawazu428 <kawazu428> |
Component: | REST | Assignee: | Denis Anisimov <ads> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | dkonecny, pjiricka |
Priority: | P3 | ||
Version: | 7.1 | ||
Hardware: | PC | ||
OS: | Linux | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: |
USERDATA table structure
glassfish v3.1.1 server log sample project structure, "as-is" without modifications |
Description
kawazu428
2012-02-14 09:32:20 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. 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. Created attachment 115789 [details]
USERDATA table structure
Created attachment 115790 [details]
glassfish v3.1.1 server log
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.
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. 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 ). web-main#130098a9af96 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 |