I am trying to create an application with angularjs and springmvc.I there are two classes Province and Comunidad.
@Entity(name="Provincia") @Table(name="T_PROVINCIA") public class Provincia implements Serializable{ private String idProvincia; private String nombre; private Comunidad refComunidad; public Provincia() { } @Id @TableGenerator(name="provinciaGen", table="T_GENERATOR", pkColumnName="ID_GENERATOR", pkColumnValue="ID_PROVINCIA", valueColumnName="ID_VALUE") @GeneratedValue(generator="provinciaGen",strategy=GenerationType.TABLE) @Column(name="ID_PROVINCIA") public String getIdProvincia() { return idProvincia; } @Column(name="NOMBRE") public String getNombre() { return nombre; } @ManyToOne(targetEntity=Comunidad.class, fetch=FetchType.LAZY) @JoinColumn(name="ID_COMUNIDAD") public Comunidad getRefComunidad() { return refComunidad; } setters ..... ..... } @Entity(name="Comunidad") @Table(name="T_COMUNIDAD") public class Comunidad implements Serializable{ @Id @TableGenerator(name="comunidadGen", table="T_GENERATOR", pkColumnName="ID_GENERATOR", pkColumnValue="ID_COMUNIDAD", valueColumnName="ID_VALUE") @GeneratedValue(generator="comunidadGen",strategy=GenerationType.TABLE) @Column(name="ID_COMUNIDAD") private String idComunidad; @Column(name="NOMBRE") private String nombre; @Column(name="SHORTNAME") private String shortName; public Comunidad() { } getters and setters ............... }
In my controller:
@RequestMapping("/userlist.json") public @ResponseBody List<Provincia> getUserList(){ return this.provinciaService.loadAllProvincias(); }
And I get this error: / * Serial analyzer not found for class org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer and
there are no properties found to create a BeanSerializer (to avoid an exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) (via the link chain: java.util.ArrayList [0] → admin.domain.Provincia ["refComunidad"] - <admin.domain. Comunidad $$ EnhancerByCGLIB $$ 68ea9e6f ["hibernateLazyInitializer"]) * /
I read about github about the hibernate module of the jackson module - this is a good choice to solve the problem problem: https://github.com/FasterXML/jackson-module-hibernate . I have included the jackson module hibernate dependency in my pom.xml
<dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-hibernate4</artifactId> <version>2.2.0</version> </dependency>
But I do not know where to configure "Hibernate4Module.Feature.FORCE_LAZY_LOADING, true". I try to follow the directions from this page http://blog.pastelstudios.com/2012/03/12/spring-3-1-hibernate-4-jackson-module-hibernate/
but I get the same error.
Is there anyone who can help me with an easy example?
user2431903
source share