Want to ask one more question.
My previous problem was solved by using fetch="join" in many-to-one tag. Mappings are:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="core.applications.ets.Attempt" table="attempts">
<id column="id" name="id" type="integer">
<generator class="increment"/>
</id>
<many-to-one fetch="join" lazy="no-proxy" class="core.applications.ets.Variant" column="variant_id" name="variant"/>
<many-to-one class="core.applications.ets.Testee" column="testee_id" name="testee"/>
<many-to-one class="core.applications.ets.Assignment" column="assignment_id" name="assignment"/>
<property column="time_start" name="timeStart" type="timestamp"/>
<property column="time_end" name="timeEnd" type="timestamp"/>
<property column="value" name="value" type="double"/>
<property column="client_hash" name="clientHash" type="string"/>
<set cascade="all" lazy="true" name="attemptTopics" order-by="id">
<key column="attempt_id"/>
<one-to-many class="core.applications.ets.AttemptTopic"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="core.applications.ets.Variant" table="variants">
<id column="id" name="id" type="integer">
<generator class="increment"/>
</id>
<property column="name" name="name" type="string"/>
<many-to-one cascade="all" class="core.applications.ets.QuestionSelector" column="question_selector_id" name="questionSelector"/>
<many-to-one cascade="all" class="core.applications.ets.VariantSelector" column="variant_selector_id" name="variantSelector"/>
<many-to-one fetch="join" lazy="no-proxy" class="core.applications.ets.Test" column="test_id" name="test"/>
<set cascade="all" lazy="true" name="variantTopics" order-by="id">
<key column="variant_id"/>
<one-to-many class="core.applications.ets.VariantTopic"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="core.applications.ets.Test" table="tests">
<id column="id" name="id" type="integer">
<generator class="increment"/>
</id>
<property column="name" name="name" type="string"/>
<property column="create_date" name="createDate" type="date"/>
<set cascade="all" lazy="true" name="assignments" order-by="id">
<key column="test_id"/>
<one-to-many class="core.applications.ets.Assignment"/>
</set>
<set cascade="all" lazy="true" name="testTopics" order-by="id">
<key column="test_id"/>
<one-to-many class="core.applications.ets.TestTopic"/>
</set>
<set cascade="all" lazy="true" name="variants" order-by="id">
<key column="test_id"/>
<one-to-many class="core.applications.ets.Variant"/>
</set>
</class>
</hibernate-mapping>
It means that relations between Attempt, Variant and Test are
Attempt *-1 Variant *-1 Test
When I trying to get an attempt hibernate generates that sql, and it's ok
Code:
Hibernate:
select
attempt0_.id as id1_2_,
attempt0_.variant_id as variant2_1_2_,
attempt0_.testee_id as testee3_1_2_,
attempt0_.assignment_id as assignment4_1_2_,
attempt0_.time_start as time5_1_2_,
attempt0_.time_end as time6_1_2_,
attempt0_.value as value1_2_,
attempt0_.client_hash as client8_1_2_,
variant1_.id as id12_0_,
variant1_.name as name12_0_,
variant1_.question_selector_id as question3_12_0_,
variant1_.variant_selector_id as variant4_12_0_,
variant1_.test_id as test5_12_0_,
test2_.id as id8_1_,
test2_.name as name8_1_,
test2_.create_date as create3_8_1_
from
attempts attempt0_
left outer join
variants variant1_
on attempt0_.variant_id=variant1_.id
left outer join
tests test2_
on variant1_.test_id=test2_.id
where
attempt0_.id=?
But object Test is proxyfied anyway...
What should I do to make hibernate load it without proxy?
P.S. I have all these problems because google-gson works only with field access and not with getters/setters. If anyone could show me some tool for JSON serialization/desirialization which uses getters/setters and is as easy as gson I will be gratefull.
Thank you.