java循环休眠选择(onetomany/manytoone)JAXR
我是Hibernate的新用户,我遇到了一个问题。当我想要获取数据库的数据时,Hibernate会做一个无限循环
我的请求:
Query q = s.createSQLQuery("SELECT resultat.* FROM (SELECT r.* FROM application a JOIN configurationapplication ca ON a.id = ca.idApplication JOIN resultat r ON r.idApplication = a.id WHERE a.etat = 1 ORDER BY dateEnregistrement DESC) resultat group by resultat.idApplication").addEntity(ResultatBO.class);
结果是:
Resultat ->
Application 1 ->
List- Configuration 1 ->
Application 1 ->
List- Configuration 1 ->
Application 1
我需要在一个应用程序中获取结果关联,在一个配置列表中获取应用程序关联,在一个应用程序中获取配置关联。这是一个循环
这是我的配置Hibernate
ApplicationBO
<class lazy="false"
name="ApplicationBO" table="application">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="libelle" column="libelle" type="string" />
<property name="etat" column="etat" type="boolean" />
<bag name="lstConfApp" lazy="false" cascade="all">
<key column="idApplication" />
<one-to-many class="ConfigurationApplicationBO"/>
</bag>
</class>
ConfigurationApplicationBO
<class lazy="true"
name="ConfigurationApplicationBO"
table="configurationapplication">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="hostID" column="host_object_id" type="int" />
<property name="serviceID" column="service_object_id" type="int" />
<property name="etat" column="etat" type="boolean" />
<property name="libelle" column="libelle" type="text" />
<many-to-one name="Application" column="idApplication" cascade="all"/>
</class>
resultabo
<class lazy="false" name="ResultatBO"
table="resultat">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="statut" column="statut" type="integer" />
<property name="dateEnregistrement" column="dateEnregistrement" type="timestamp" />
<property name="infoComplementaire" column="infoComplementaire" type="string" />
<many-to-one name="application" column="idApplication"/>
</class>
我从不使用关系配置应用程序。getApplication()。当我保存/更新/删除数据时,我只有这个属性应用程序
我也希望在应用程序中得到一个结果。etat=1,并且至少有个计数(configuration.etat=1)>;0
你有办法解决这个问题吗。 谢谢
抱歉我的英语不好:D
编辑1:
请求的结果将在我的API JAXRS中公开。我有这个错误,对我来说问题是休眠org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[0]->ResultatBO["application"]->ApplicationBO_$$_javassist_1["handler"])
编辑2:
密码
@GET
@Produces("application/json")
public Response get() {
List<ResultatBO> lstRes = ContextServiceImpl.getInstance().getStatusApplications( HibernateUtil.getSessionFactory().getCurrentSession()); GenericEntity<List<ResultatBO>> entity;
entity = new GenericEntity<List<ResultatBO>>(lstRes) { };
return Response.ok(entity).build(); }
编辑3:
问题解决了。塔克斯。我使用了旧版本的代码,但忘了更新版本:s
问题出在我的hbm上。xml文件模式为true时,我修改了false处的值,并添加了注释@JsonIgnore
共 (0) 个答案