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.
This problem is't in REST support, but in hibernate class library which Netbeans define. This library contain standard Hibernate dependencies: asm-attrs.jar asm.jar cglib-2.1.3.jar Jersey use ASM library also, but in 3.1 version which is not compatible with version from hibernate. I think, that best solution is remove asm-attrs.jar, asm.jar and cglib-2.1.3.jar from Hibernate class library and use cglib-nodep-2.1_3.jar. Steps to reproduce this problem: 1. Create web project 2. Create Persitence Unit with Hibernate and obtain some entity class from Database 3. Generate RESTfull web services from this entity class 4. Run application Tested with Build 20080814104752
Tomas Prochazka (the reporter) says the following workaround works for him on Tomcat (based on information from CZJUG mailing list): initialization of entity manager needs to be rewritten as follows: emf = Persistence.createEntityManagerFactory(DEFAULT_PU); em = emf.createEntityManager(); utx = em.getTransaction();
Ayub, please take care of this one since you tried to get things to work with hibernate before. BTW, I think the lazy instantiation problem is gone now since we no longer close the persistence factory after each request.
On Glassfish I see two issues 1. The lib issue is already mentioned, for which I have filed an issue 145589 against hibernatelibs module 2. Getting exception accessing collections (after locally fixing hibernatelib module with the suggested fix from 145589) failed to lazily initialize a collection of role: customerdb.DiscountCode.customerCollection, no session or session was closed (See attachment for stacktrace) Steps to reproduce. 1. Checkout NB 6.5 from mercurial, do build (cd nbbuild; ant) 2. Locally fix hibernatelib module as suggested in 145589, do build hibernatelib (cd hibernatelib; ant) 3. Run nbbuild/netbeans/bin/netbeans 4. Create 'CustomerDB' REST web services sample app 5. Add "Hibernate" as framework to this app (by right click on the CustomerDB prject node and selecting 'Properties' 6. Change /Configuration Files/persistence.xml as follows <!--<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="CustomerDBPU" transaction-type="JTA"> <jta-data-source>jdbc/sample</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties/> </persistence-unit> </persistence>--> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="CustomerDBPU" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/sample</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> </persistence-unit> </persistence> 7. Now run 'Test RESTful Web Services' action, you will see a browser open up with Test client to test RESTful Web Services. 8. Click on 'customers' link on the left side menu, then click 'Test' button on the right side. 9. Expand node 'customers', click on customerId node, then enter '1' for customerId, then click 'Test' button. This time you should see the exception attached.
Created attachment 68996 [details] exception stracktrace
Created attachment 68997 [details] Oops wrong file attached earlier, this has the exception
Basically, the issue with lazy fetching is that it needs to be done instead of a hibernate session or transaction. In our case, the serialization of the entities are done outside of the transaction (after the entities are returned from the get method). It is already too late. See the following hibernate documentation for detail: http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#performance-fetching-lazy According to the hibernate documentation, there are two way to work around the issue, one is to have the http session close the transaction at the very end or explicitly fetch all the necessary data before closing the transaction. For the first approach, we have no control over the session. The second approach requires us to generate code to explicitly fetch all the relationship objects down to the level specified by the expandLevel flag. We can probably generate some code in our converter to do this. I'll give that a try.
I just checked in the fixes for the lazy instantiation problem. I also got things to work with Spring+Hibernate. However, there are still some issues related to tomcat. I'll look into it further after I close some other issues first.
REST services still not working with Hibernate JPA 2.0. See the issue 233726.
Closed, as both related bugs (bug 145589 and bug 233726) were marked as fixed. At least with GlassFish 3 Hibernate 2.0 works now.