I'm trying to have a lazy list populate with only objects that are active. Basically a Terminal object has a list of persons and the Person object has a isActive member. When I load the list of persons I do not want to specify in every HQL query to load only the active ones.
After a look at the hibernate documentation and Gavin's book, it looks like the "check" attribute is what I need, but it doesn't seem to be affecting anything no matter what I set it to all the persons (active or deactive) are being loaded.
Here is what the bag mapping looks like for the Terminal object's List<Person> persons member:
Code:
<bag name="persons" lazy="true" table="person" cascade="all-delete-orphan" check="isActive = true">
<key column="terminal_id" />
<one-to-many class="com.borderconnect.domain.person.Person"/>
</bag>
Am I using the check attribute wrong? Even if I put "1=2" in there it doesn't effect the query or do anything?
Thanks in advance!
Hibernate version:3
Mapping documents:Code:
<bag name="persons" lazy="true" table="person" cascade="all-delete-orphan" check="isActive = true">
<key column="terminal_id" />
<one-to-many class="com.borderconnect.domain.person.Person"/>
</bag>
Code between sessionFactory.openSession() and session.close():N/A
Full stack trace of any exception that occurs:N/A
Name and version of the database you are using:Postgres 8.1
The generated SQL (show_sql=true):Code:
[10:48:21,866]DEBUG SQL:346 - select carrier0_.id as id37_, carrier0_.working_version_id as working2_37_, carrier0_.mailbox_id as mailbox3_37_, carrier0_.promotion_code as promotion4_37_, carrier0_.account_state as account5_37_, carrier0_.registration_date as registra6_37_, carrier0_.verification_date as verifica7_37_, carrier0_.approval_date as approval8_37_, carrier0_.default_pars_position as default9_37_, carrier0_.default_carrier_code_id as default10_37_, carrier0_.default_sequence_warning_number as default11_37_ from carrier carrier0_ where carrier0_.id=?
[10:48:21,897]DEBUG SQL:346 - select carrierver0_.id as id38_1_, carrierver0_.carrier_id as carrier2_38_1_, carrierver0_.name as name38_1_, carrierver0_.billing_address_line_1 as billing4_38_1_, carrierver0_.billing_address_line_2 as billing5_38_1_, carrierver0_.billing_city as billing6_38_1_, carrierver0_.billing_postal_code as billing7_38_1_, carrierver0_.billing_province as billing8_38_1_, carrierver0_.billing_country_id as billing9_38_1_, country1_.id as id5_0_, country1_.name as name5_0_, country1_.code as code5_0_ from carrier_version carrierver0_ left outer join country country1_ on carrierver0_.billing_country_id=country1_.id where carrierver0_.id=?
[10:48:21,928]DEBUG SQL:346 - select amendments0_.carrier_id as carrier2_2_, amendments0_.id as id2_, amendments0_.id as id38_1_, amendments0_.carrier_id as carrier2_38_1_, amendments0_.name as name38_1_, amendments0_.billing_address_line_1 as billing4_38_1_, amendments0_.billing_address_line_2 as billing5_38_1_, amendments0_.billing_city as billing6_38_1_, amendments0_.billing_postal_code as billing7_38_1_, amendments0_.billing_province as billing8_38_1_, amendments0_.billing_country_id as billing9_38_1_, country1_.id as id5_0_, country1_.name as name5_0_, country1_.code as code5_0_ from carrier_version amendments0_ left outer join country country1_ on amendments0_.billing_country_id=country1_.id where amendments0_.carrier_id=?
[10:48:21,928]DEBUG SQL:346 - select terminals0_.carrier_id as carrier2_3_, terminals0_.id as id3_, terminals0_.id as id41_2_, terminals0_.carrier_id as carrier2_41_2_, terminals0_.address_line_1 as address3_41_2_, terminals0_.address_line_2 as address4_41_2_, terminals0_.city as city41_2_, terminals0_.postal_code as postal6_41_2_, terminals0_.province as province41_2_, terminals0_.country_id as country8_41_2_, terminals0_.phone_number as phone9_41_2_, terminals0_.fax_number as fax10_41_2_, terminals0_.type as type41_2_, terminals0_.time_zone_id as time12_41_2_, terminals0_.is_active as is13_41_2_, country1_.id as id5_0_, country1_.name as name5_0_, country1_.code as code5_0_, timezone2_.id as id0_1_, timezone2_.gmt as gmt0_1_, timezone2_.java_id as java3_0_1_, timezone2_.name as name0_1_ from terminal terminals0_ left outer join country country1_ on terminals0_.country_id=country1_.id left outer join time_zone timezone2_ on terminals0_.time_zone_id=timezone2_.id where terminals0_.carrier_id=?
[10:48:21,944]DEBUG SQL:346 - select persons0_.terminal_id as terminal8_1_, persons0_.id as id1_, persons0_.id as id6_0_, persons0_.first_name as first2_6_0_, persons0_.last_name as last3_6_0_, persons0_.title as title6_0_, persons0_.email_address as email5_6_0_, persons0_.phone_number as phone6_6_0_, persons0_.phone_extension as phone7_6_0_, persons0_.terminal_id as terminal8_6_0_, persons0_.username as username6_0_, persons0_.password as password6_0_, persons0_.role as role6_0_, persons0_.login_entries as login12_6_0_, persons0_.is_active as is13_6_0_, persons0_.use_status_auto_email as use14_6_0_, persons0_.listing_max_results as listing15_6_0_, persons0_.use_refresh as use16_6_0_, persons0_.refresh_time as refresh17_6_0_, persons0_.highlight_new_shipments as highlight18_6_0_, persons0_.use_sequence_auto_email as use19_6_0_ from person persons0_ where persons0_.terminal_id=?
[10:48:21,960]DEBUG SQL:346 - select persons0_.terminal_id as terminal8_1_, persons0_.id as id1_, persons0_.id as id6_0_, persons0_.first_name as first2_6_0_, persons0_.last_name as last3_6_0_, persons0_.title as title6_0_, persons0_.email_address as email5_6_0_, persons0_.phone_number as phone6_6_0_, persons0_.phone_extension as phone7_6_0_, persons0_.terminal_id as terminal8_6_0_, persons0_.username as username6_0_, persons0_.password as password6_0_, persons0_.role as role6_0_, persons0_.login_entries as login12_6_0_, persons0_.is_active as is13_6_0_, persons0_.use_status_auto_email as use14_6_0_, persons0_.listing_max_results as listing15_6_0_, persons0_.use_refresh as use16_6_0_, persons0_.refresh_time as refresh17_6_0_, persons0_.highlight_new_shipments as highlight18_6_0_, persons0_.use_sequence_auto_email as use19_6_0_ from person persons0_ where persons0_.terminal_id=?
Debug level Hibernate log excerpt:N/A
Code: