Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Spring Flex and hibernate issue LIE

  1. #1

    Default Spring Flex and hibernate issue LIE

    Hello,

    I am having an issue integrating spring, flex and hibernate within a portion of my application.

    My application is using blazeds for the AMF serialization. I will try to break down what is happening as best I can:

    1). a user makes a request to do "something" on my flex client.
    2). The flex client invokes a service object managed by spring.
    - this service object is wrapped around a OncePerRequest filter that opens the hibernate session once per request.
    3). the service object then makes use of springs Event Publishing mechanism by publishing an event with the SimpleAsyncTaskExecutor.
    4). Now my event listener will be kicked off in a separate thread when the event is published
    5). inside my event listener, i do some more work and finally publish a message back to flex using the spring flex integration message template.

    Now here is where the problem lies.

    During the serialization of the message i post to flex, I am getting Lazy Initialization Exceptions.

    My question is, what is the best way to manage this situation? inside my event listener, I can bind a hibernate session to the executing thread, but then how do i close it? once the message is published to the flex client, the session needs to be opened in order for serialization to complete.

    Any help would be greatly appreciated, and please let me know if you want me to clarify things further.

    -Roy

  2. #2
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    Have you tried this with Spring BlazeDS 1.5M1? We've added some special Hibernate serialization support there that should prevent these errors without having to worry about re-binding the Session.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  3. #3

    Default

    Jeremy,

    Thanks for the suggestion, I will give this upgrade a shot once things calm down with my app. I will reply to this post to see if it addressed my issue.

    In the mean time, I added a quick hack that will just unproxy the persistent value object before sending over the wire to flex. I know this is not the optimal solution, but it is a working hack.

  4. #4
    Join Date
    Nov 2010
    Posts
    2

    Default

    Quote Originally Posted by jeremyg484 View Post
    Have you tried this with Spring BlazeDS 1.5M1? We've added some special Hibernate serialization support there that should prevent these errors without having to worry about re-binding the Session.
    Hi,

    I'm having a hard time getting this work. If I read the documentation correctly, Spring BlazeDS 1.5M1 should fix the lazy loading problem automatically. It seems not, and even if I declare the HibernateConfigProcessor manually in my context-file as follows...

    Code:
    <flex:message-broker>
    	<flex:config-processor ref="myHibernateConfigProcessor" />
    	<flex:secured>
    		<flex:secured-channel access="ROLE_USER" channel="my-amf"/>
    	</flex:secured>
    </flex:message-broker>
    
    <bean id="myHibernateConfigProcessor" class="org.springframework.flex.core.io.HibernateConfigProcessor">
    	<property name="conversionService" ref="myConversionService" />
    	<property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    	
    <bean id="myConversionService" class="org.springframework.core.convert.support.GenericConversionService"/>
    ...it still seems that it doesn't work. When I fetch an entity that has a collection of items, Flex throws me the following error:

    [RPC Fault faultString="failed to lazily initialize a collection of role: xxxx.xxxx.xxxx.model.entity.Person.issueLinkers, no session or session was closed"
    And Tomcat gives the following output:

    [BlazeDS][ERROR] Exception occurred during serialization: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: xxxx.xxxx.xxxx.model.en
    tity.Person.issueLinkers, no session or session was closed
    at org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationException(AbstractPersi stentCollection.java:383)
    at org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationExceptionIfNotConnected (AbstractPersistentCollection.java:375)
    at org.hibernate.collection.AbstractPersistentCollect ion.readSize(AbstractPersistentCollection.java:122 )
    at org.hibernate.collection.PersistentBag.size(Persis tentBag.java:248)
    at org.springframework.core.style.DefaultValueStyler. style(DefaultValueStyler.java:104)
    at org.springframework.core.style.DefaultValueStyler. style(DefaultValueStyler.java:72)
    at org.springframework.core.style.StylerUtils.style(S tylerUtils.java:47)
    at org.springframework.core.convert.support.GenericCo nversionService.convert(GenericConversionService.j ava:159)
    at org.springframework.flex.core.io.SpringPropertyPro xy.getValue(SpringPropertyProxy.java:91)
    at flex.messaging.io.amf.Amf3Output.writePropertyProx y(Amf3Output.java:601)
    at flex.messaging.io.amf.Amf3Output.writeCustomObject (Amf3Output.java:532)
    at flex.messaging.io.amf.Amf3Output.writeObject(Amf3O utput.java:207)
    at flex.messaging.messages.AbstractMessage.writeExter nalBody(AbstractMessage.java:705)
    at flex.messaging.messages.AbstractMessage.writeExter nal(AbstractMessage.java:435)
    at flex.messaging.messages.AsyncMessage.writeExternal (AsyncMessage.java:140)
    at flex.messaging.messages.AcknowledgeMessage.writeEx ternal(AcknowledgeMessage.java:94)
    at flex.messaging.messages.AcknowledgeMessageExt.writ eExternal(AcknowledgeMessageExt.java:55)
    at flex.messaging.io.amf.Amf3Output.writePropertyProx y(Amf3Output.java:594)
    at flex.messaging.io.amf.Amf3Output.writeCustomObject (Amf3Output.java:532)
    at flex.messaging.io.amf.Amf3Output.writeObject(Amf3O utput.java:112)
    at flex.messaging.io.amf.Amf0Output.writeObject(Amf0O utput.java:206)
    at flex.messaging.io.amf.AmfMessageSerializer.writeOb ject(AmfMessageSerializer.java:196)
    at flex.messaging.io.amf.AmfMessageSerializer.writeBo dy(AmfMessageSerializer.java:186)
    at flex.messaging.io.amf.AmfMessageSerializer.writeMe ssage(AmfMessageSerializer.java:142)
    at flex.messaging.endpoints.amf.SerializationFilter.i nvoke(SerializationFilter.java:198)
    at flex.messaging.endpoints.BaseHTTPEndpoint.service( BaseHTTPEndpoint.java:291)
    at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCG LIB$$1f84238.service(<generated>)
    at org.springframework.flex.servlet.MessageBrokerHand lerAdapter.handle(MessageBrokerHandlerAdapter.java :108)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:788)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:717)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:560)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFi lter.doFilterInternal(CharacterEncodingFilter.java :88)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 343)
    at org.springframework.security.web.access.intercept. FilterSecurityInterceptor.invoke(FilterSecurityInt erceptor.java:109)
    at org.springframework.security.web.access.intercept. FilterSecurityInterceptor.doFilter(FilterSecurityI nterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.access.ExceptionT ranslationFilter.doFilter(ExceptionTranslationFilt er.java:97)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.session.SessionMa nagementFilter.doFilter(SessionManagementFilter.ja va:100)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.authentication.An onymousAuthenticationFilter.doFilter(AnonymousAuth enticationFilter.java:78)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.servletapi.Securi tyContextHolderAwareRequestFilter.doFilter(Securit yContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.savedrequest.Requ estCacheAwareFilter.doFilter(RequestCacheAwareFilt er.java:35)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.context.SecurityC ontextPersistenceFilter.doFilter(SecurityContextPe rsistenceFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.web.filter.RequestContextFilte r.doFilterInternal(RequestContextFilter.java:83)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.FilterChainProxy. doFilter(FilterChainProxy.java:149)
    at org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(DelegatingFilterProxy.java:237)
    at org.springframework.web.filter.DelegatingFilterPro xy.doFilter(DelegatingFilterProxy.java:167)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
    So it seems it's using the ConversionService, as the line

    at org.springframework.core.convert.support.GenericCo nversionService.convert(GenericConversionService.j ava:159)
    seems to imply, but for some reason it's not working.

    So I guess the question is am I missing something here? Are there any tutorials on how to get this to work correctly, because I couldn't find any.

    Any help would be greatly appreciated!

    Best regards,
    Jukka Hämäläinen

  5. #5
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    Providing your own ConversionService like that definitely won't get the job done, because it doesn't include the specialized converters that we provide.

    If you take a look at the source for HibernateConfigProcessor, you'll see what I mean.

    That said, you ideally shouldn't need to manually provide the HibernateConfigProcessor at all, unless maybe you have more than one SessionFactory. It would be more helpful if you could explain what errors you get when you don't manually include it.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  6. #6

    Default

    I got the same issue without manually configuring:
    Spring 3.0.3.RELEASE
    Spring flex 1.5.0.M1
    Hibernate 3.5.1-Final

    Code:
    2010-11-12 09:57:57,377 [main] INFO  org.springframework.flex.core.io.HibernateConfigProcessor - Hibernate detected and AMF serialization support automatically installed successfully.
    ..
    ..
    ..
    ..
    
    [BlazeDS]Adapter 'java-object' called 'null.getAll(java.util.Arrays$ArrayList (Collection size:0)
    )'
    2010-11-12 09:58:40,520 [http-8080-1] DEBUG org.springframework.flex.core.io.SpringPropertyProxy - Property names for com.xxx.xxx.domain.Country@86da3fbe : [ID, isoCode, name, states]
    2010-11-12 09:58:40,520 [http-8080-1] DEBUG org.springframework.flex.core.io.SpringPropertyProxy - Introspected type of property 'ID' on instance com.xxx.xxx.domain.Country@86da3fbe is class java.lang.Long
    2010-11-12 09:58:40,520 [http-8080-1] DEBUG org.springframework.flex.core.io.SpringPropertyProxy - Actual type of value for property 'ID' on instance com.xxx.xxx.domain.Country@86da3fbe is class java.lang.Long
    2010-11-12 09:58:40,520 [http-8080-1] DEBUG org.springframework.flex.core.io.SpringPropertyProxy - Introspected type of property 'isoCode' on instance com.xxx.xxx.domain.Country@86da3fbe is class java.lang.String
    2010-11-12 09:58:40,520 [http-8080-1] DEBUG org.springframework.flex.core.io.SpringPropertyProxy - Actual type of value for property 'isoCode' on instance com.xxx.xxx.domain.Country@86da3fbe is class java.lang.String
    2010-11-12 09:58:40,520 [http-8080-1] DEBUG org.springframework.flex.core.io.SpringPropertyProxy - Introspected type of property 'name' on instance com.xxx.xxx.domain.Country@86da3fbe is class java.lang.String
    2010-11-12 09:58:40,520 [http-8080-1] DEBUG org.springframework.flex.core.io.SpringPropertyProxy - Actual type of value for property 'name' on instance com.xxx.xxx.domain.Country@86da3fbe is class java.lang.String
    2010-11-12 09:58:40,520 [http-8080-1] ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.xxx.xxx.domain.Country.states, no session or session was closed
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.xxx.xxx.domain.Country.states, no session or session was closed
    	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
    	at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
    	at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119)
    	at org.hibernate.collection.PersistentSet.size(PersistentSet.java:162)
    	at java.util.HashSet.<init>(HashSet.java:99)
    	at com.xxx.xxx.domain.Country.getStates(Country.java:56)
    	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:585)
    	at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:734)
    	at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:694)
    	at org.springframework.flex.core.io.SpringPropertyProxy.getValue(SpringPropertyProxy.java:80)
    	at flex.messaging.io.AbstractProxy.getValue(AbstractProxy.java:146)
    	at flex.messaging.util.ToStringPrettyPrinter.prettifyComplexType(ToStringPrettyPrinter.java:191)
    	at flex.messaging.util.BasicPrettyPrinter.internalPrettify(BasicPrettyPrinter.java:95)
    	at flex.messaging.util.ToStringPrettyPrinter.prettifyComplexType(ToStringPrettyPrinter.java:106)
    	at flex.messaging.util.BasicPrettyPrinter.internalPrettify(BasicPrettyPrinter.java:95)
    	at flex.messaging.util.BasicPrettyPrinter.prettify(BasicPrettyPrinter.java:57)
    	at flex.messaging.util.ToStringPrettyPrinter.prettify(ToStringPrettyPrinter.java:67)
    	at flex.messaging.log.Logger.log(Logger.java:383)
    	at flex.messaging.log.Logger.log(Logger.java:359)
    	at flex.messaging.log.Logger.debug(Logger.java:140)
    	at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:193)
    	at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1400)
    	at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:1005)
    	at flex.messaging.endpoints.AbstractEndpoint$$FastClassByCGLIB$$1a3ef066.invoke(<generated>)
    	at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    	at org.springframework.flex.core.MessageInterceptionAdvice.invoke(MessageInterceptionAdvice.java:66)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:124)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.Cglib2AopProxy$FixedChainStaticTargetInterceptor.intercept(Cglib2AopProxy.java:572)
    	at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$6e0bbc4.serviceMessage(<generated>)
    	at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:103)
    	at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
    	at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:44)
    	at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
    	at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:166)
    	at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:291)
    	at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$6e0bbc4.service(<generated>)
    	at org.springframework.flex.servlet.MessageBrokerHandlerAdapter.handle(MessageBrokerHandlerAdapter.java:108)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:774)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)
    	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)
    	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

  7. #7
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    Now we're getting closer...something looks a little strange there. Would you mind showing the code for your getStates method? Also, is there anything special going on in your Hibernate mapping, or is it just a default one-to-many mapping?
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  8. #8

    Default

    It is JPA mapping with hibernate jars. Persistence unit is configured using org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean. Nothing special, just a simple OneToMany, ManyToOne mapping at the FIELD level annotations.
    --
    @Entity
    @Table(name = "COUNTRY")
    public class Country implements BaseEntity {
    private static final long serialVersionUID = -3821882442388595980L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "country_id")
    private Long ID;
    @Column(name = "iso_country_code", length = 10)
    private String isoCode;
    @Column(name = "country_name", length = 100, nullable = false)
    private String name;
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "country")
    private Set<State> states = new HashSet<State>();



    --
    @Entity
    @Table(name = "STATE")
    public class State implements BaseEntity {

    private static final long serialVersionUID = 9169007521106341318L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "state_id")
    private Long ID;
    @Column(name = "state_cd", length = 2, nullable = false)
    private String code;
    @Column(name = "state_name", length = 50, nullable = false)
    private String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "country_id")
    private Country country;

  9. #9
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    I'd still like to see your getStates() method, as that is where the Hibernate proxy is blowing up. I'm trying to isolate whether it's something in the way you're initializing the collection, or whether it's in our code. I suppose it could be that some of the Hibernate proxy behavior has changed in later versions from what we're expecting. (We've been using Hibernate 3.3.1 as the baseline.)
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  10. #10

    Default

    I did not think about that. My code for get states is
    public Set<State> getStates() {
    return new HashSet<State>(this.states);
    }
    I am trying to protect my private state collection from being manipulated by others, so I am putting it in new hash set.
    I was assuming that springproxy will try to access it at FIELD level, not through getXXX methods.
    Probably I should try to return the collection as it is.
    Last edited by darpansharma; Nov 19th, 2010 at 12:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •