-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: <many-to-one> with an immutable table : cached?
PostPosted: Thu May 13, 2004 3:51 pm 
Beginner
Beginner

Joined: Thu May 06, 2004 4:06 pm
Posts: 25
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 : ProjectTable

Code:
<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();   
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.