-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Returning Hibernate Entities in JAX-WS response
PostPosted: Mon Jun 29, 2009 4:39 am 
Newbie

Joined: Mon Jun 08, 2009 4:32 am
Posts: 3
Hi all,

I'd like to return some Hibernate 3 entities in the responses of WebServices exposed throught JAX-WS RI in Tomcat 5.5.

Because I need to do some property lazy fetching on this entities, I use Javassist instrumentation. Basically, it automatically adds new properties to my entities. Types of this new properties are not simple types or classes but they are interfaces.
The problems begin when I deploy the solution in Tomcat because: 1/ JAXB (used by JAX-WS RI) can't handle interfaces (to generate WSDL I suppose) and 2/ I don't want my WS client to see all this generated properties.

Do you have some ideas how to resolve this problem?

It may be a bad design to return the hibernate objects in the WebServices but, in my case, this WebServices are precisely a data layer (to search, load and persists objects).

Here is an extract of the exception I get when deploying the solution:

Code:
GRAVE: WSSERVLET11: failed to parse runtime descriptor: javax.xml.ws.WebServiceException: Unable to create JAXBContext due to the security restriction
javax.xml.ws.WebServiceException: Unable to create JAXBContext due to the security restriction
   at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:131)
   at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:63)
   at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:224)
   at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:308)
   at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:174)
   [...]
   at java.lang.Thread.run(Thread.java:595)
Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
org.hibernate.bytecode.javassist.FieldHandler is an interface, and JAXB can't handle interfaces.
   this problem is related to the following location:
      at org.hibernate.bytecode.javassist.FieldHandler
      at public org.hibernate.bytecode.javassist.FieldHandler com.connectivit.bpihub.dal.RoutingRule.getFieldHandler()
      at com.connectivit.bpihub.dal.RoutingRule
      at public com.connectivit.bpihub.dal.RoutingRule com.connectivit.bpihub.webservices.structures.MessageToProcess.getRoutingRule()
      [...]
      at com.connectivit.bpihub.webservices.jaxws.GetMessageListToProcessResponse
org.hibernate.bytecode.javassist.FieldHandler does not have a no-arg default constructor.
   this problem is related to the following location:
      at org.hibernate.bytecode.javassist.FieldHandler
      at public org.hibernate.bytecode.javassist.FieldHandler com.connectivit.bpihub.dal.RoutingRule.getFieldHandler()
      [...]

   at java.security.AccessController.doPrivileged(Native Method)
   at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:124)
   ... 24 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
org.hibernate.bytecode.javassist.FieldHandler is an interface, and JAXB can't handle interfaces.
   this problem is related to the following location:
      at org.hibernate.bytecode.javassist.FieldHandler
      at public org.hibernate.bytecode.javassist.FieldHandler com.connectivit.bpihub.dal.RoutingRule.getFieldHandler()
      [...]

   at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
   at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:422)
   at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:270)
   at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:103)
   at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:89)
   at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:126)
   at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:125)
   ... 26 more


Thanks for your help,

Florent


Top
 Profile  
 
 Post subject: Re: Returning Hibernate Entities in JAX-WS response
PostPosted: Tue Jun 30, 2009 8:59 am 
Newbie

Joined: Mon Jun 08, 2009 4:32 am
Posts: 3
I found a quite nice solution to my problem :

I annotated my classes with:

@XmlAccessorType(XmlAccessType.NONE) // from "javax.xml.bind.annotation" package

to tell JAXB to ignore any field or property by default, then I annotated each property of my classes with:

@XmlElement

This way, all property added at compilation time are not annotated with the @XmlElement and JAXB don't try to export them in the XML.


Top
 Profile  
 
 Post subject: Re: Returning Hibernate Entities in JAX-WS response
PostPosted: Sun Aug 08, 2010 12:08 pm 
Newbie

Joined: Tue Apr 27, 2010 5:18 pm
Posts: 19
I'm trying to do the same thing.
How do you get around the problem of the lazy collections.

I often have objects (A), which have lists (B) (in other tables).

Normally you'd have you WebService
Code:
@WebMethod
public HibernateObject testMethod()
{
   Session session = HibernateUtil.openSession();
   HibernateObject obj = session.getHibernateObject(...)
   session.close();
   return obj;
}


When I try to return A, it gives me (logically) the error, LazyInitializationException ....
How did you solve this problem?

Thanks

Martin


Top
 Profile  
 
 Post subject: Re: Returning Hibernate Entities in JAX-WS response
PostPosted: Thu Dec 16, 2010 2:53 am 
Newbie

Joined: Tue Apr 27, 2010 5:18 pm
Posts: 19
anyone have any ideas? I'm still stuck here.


Top
 Profile  
 
 Post subject: Re: Returning Hibernate Entities in JAX-WS response
PostPosted: Thu Jun 09, 2011 1:27 pm 
Newbie

Joined: Tue Apr 27, 2010 5:18 pm
Posts: 19
posting my own solution for other JAX-WS + lazy hibernate devs.
http://forums.oracle.com/forums/message.jspa?messageID=9221962#9221962

Martin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.