Could not initialize proxy

1 resposta
J

Pessoal, bom dia.

Alguem pode me ajudar com o erro abaixo?

Estou usando JPA + HIBERNATE + VRAPTOR

Classes:
a) Feature.java
b) A Feature possui FeatureLicense.java tendo um relacionamento OneToOne

A sequência do processo:
a) É aberta uma página para digitação das chaves de uma licença ( FeatureLicense.java)
b) Assim, o controller recebe a instância de Feature/FeatureLicense pelo mapeamento das classes e seus atributos. Exemplo: feature.license.keyACode/ feature.license.keyBCode
c) Quando o controller recebe as instâncias descritas acima, os dados da feature neste momento estão vazias, por isso faço uma pesquisa da feature como detached(featureGov) e em seguida faço um set em feature com os dados de featureGov. Neste parse atualizo apenas o ID, o código da feature e em licença, atualizo a feature por causa do relacionamento.

Depois deste processo, serializo o objeto para atualizar alguns campos indicando se a chave é válida e data de expiração. Isto antes de salvar os dados na base.
a) result.use(ExtJSJson.class).from(feature).success(true).serialize();

Nesta serialização está gerando o erro abaixo:

Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session

at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)

at br.com.caelum.vraptor.serialization.HibernateProxyInitializer.initialize(HibernateProxyInitializer.java:39)

at br.com.caelum.vraptor.serialization.xstream.XStreamSerializer$1.marshal(XStreamSerializer.java:282)

at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)

at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)

at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)

at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)

at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)

at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)

at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)

at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)

at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)

at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)

at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:157)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:148)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.visit(AbstractReflectionConverter.java:118)

at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:129)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:100)

at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:58)

at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:68)

at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:78)

at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:63)

at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:98)

at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:38)

at com.thoughtworks.xstream.XStream.marshal(XStream.java:837)

at com.thoughtworks.xstream.XStream.marshal(XStream.java:826)

at com.thoughtworks.xstream.XStream.toXML(XStream.java:801)

at br.com.caelum.vraptor.serialization.xstream.XStreamSerializer.serialize(XStreamSerializer.java:259)

at br.com.caelum.vraptor.util.extjs.DefaultExtJson.serialize(DefaultExtJson.java:88)

at br.com.eccox.gov.controller.LicenseController.check(LicenseController.java:68)

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:597)

at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:61)

Obrigado.

Abs

1 Resposta

J

Pessoal, boa tarde.

Consegui achar o problema. Como o vraptor é Open Session in View, tem uma instância da classe Feature gerenciada pelo jpa e antes de salvar faço um parse de alguns atributos com uma instância de Feature detached. Como existe um relacionamento de um para um entre Feature e FeatureLicense, nesta setei errado o objeto Feature de relacionamento, isto é, ao invés de setar a instância persistente, sete a detached, ocasionando o erro.
Corrigi e funcionou.

Obrigado a todos.

Abs

Criado 7 de dezembro de 2011
Ultima resposta 7 de dez. de 2011
Respostas 1
Participantes 1