Hello,
I am just wondering if someone could help me with some concepts! I am just wondering if there is a way to prevent, what I think are, unnecessary SELECT statements, that should/could they be cached in some way?
I currently have a large number of tables, that have an associated 'type' table. For example, I have a 'project' table, that has an association to a 'project_type' table (hbm below).
For the project_type class, i have set mutable="false", as well as setting the jcs-cache useage to "read-only". Since this table will not change.
Here is my question, when i get an iterator of Projects, and remove a Project, it hits the database (SELECT on project_type table),
each and every time, to get the associated ProjectType object:
Code:
11:22:13,386 DEBUG SQL:237 - select projecttyp0_.id as id0_, projecttyp0_.name...
This totally makes sense...!!! But....
Questions:
1. Does it have to if ProjectType is immutable, and 'read-only'? ...can it be cached in some way (to work with the above scenerio)? if so how?(The cache for session.load( .. ) on PartyType works great!)
2. If it can't be cached, can the instantiation of the ProjectType be made Lazy? untill project.getProjectType( ) is called?
Example Mapping : ProjectTableCode:
<hibernate-mapping>
<class name="com.Project" table="project">
<id name="id" type="long" column="id">
<generator class="identity"/>
</id>
<!-- project.type_id = project_type.id -->
<many-to-one name="projectType" class="com.ProjectType" column="type_id" not-null="true"/>
..
</class>
</hibernate-mapping>
Example Mapping : Project Type Table (immutable, read-only)Code:
<hibernate-mapping>
<class name="com.ProjectType" table="project_type" mutable="false">
<jcs-cache usage="read-only"/>
<id name="id" type="long" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name" type="string"/>
..
</class>
</hibernate-mapping>
Code Example:Code:
Project project;
Iterator projects =
dbSession.iterate(
"FROM Project p WHERE p.projectType.id = 1"
);
while( projects.hasNext() ) {
project = (Project) projects.next();
}