-->
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.  [ 6 posts ] 
Author Message
 Post subject: Loading values from a lookup table
PostPosted: Sun Dec 03, 2006 12:06 am 
Newbie

Joined: Mon Jul 10, 2006 1:47 am
Posts: 8
I have a table USER. A USER can have many possible types. These possible types are in a lookup table USER_TYPE I would like to keep that association in Hibernate by creating a Hibernate POJO for USER_TYPE. But the problem is that whenevre the there is an access to either:
    the getType() of the User object or
    the equals and hashcode methods (type is a property of the user which uniquely defines it)


There is a SQL generated to access the DB. IS there any way to avoid/cache this since this information (the UserType) always has the same values

Hibernate version:
3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html



    Last edited by regencypark2 on Sun Dec 03, 2006 2:03 am, edited 1 time in total.

    Top
     Profile  
     
     Post subject: Loading values from a lookup table
    PostPosted: Sun Dec 03, 2006 12:55 am 
    Beginner
    Beginner

    Joined: Thu Apr 27, 2006 12:19 pm
    Posts: 33
    Location: Seattle, WA
    This sounds like a many-to-one relationship. What are your mapping files for user and user_type?


    Top
     Profile  
     
     Post subject:
    PostPosted: Sun Dec 03, 2006 1:16 am 
    Newbie

    Joined: Mon Jul 10, 2006 1:47 am
    Posts: 8
    User.hbm.xml:

    <hibernate-mapping>
    <class name="com.gen.User" table="USER" catalog="gen">
    <id name="identityId" type="java.lang.Integer">
    <column name="IDENTITY_ID" />
    <generator class="native" />
    </id>
    <many-to-one name="typeOf" class="com.gen.UserType" fetch="select">
    <column name="USER_TYPE_ID" />
    </many-to-one>
    ... ...
    </class>
    </hibernate-mapping>


    UserType.hbm.xml

    <hibernate-mapping>
    <class name="com.gen.UserType" table="USER_TYPE" catalog="gen">
    <id name="USER_TYPE" type="java.lang.Integer">
    <column name="USER_TYPE_ID" />
    <generator class="native" />
    </id>

    <property name="name" type="java.lang.String">
    <column name="TYPE_NAME" not-null="true" />
    </property>
    ... ...
    </class>
    </hibernate-mapping>


    Top
     Profile  
     
     Post subject:
    PostPosted: Sun Dec 03, 2006 1:49 am 
    Senior
    Senior

    Joined: Tue Aug 23, 2005 8:52 am
    Posts: 181
    Will your UserType class ever change? If not, you can make the class immutable using mutable="false" and make the cache a read-only cache. Refer to
    file:///apps/hibernate-3.2/doc/reference/en/html_single/index.html#performance-cache-readonly


    Top
     Profile  
     
     Post subject:
    PostPosted: Sun Dec 03, 2006 2:04 am 
    Newbie

    Joined: Mon Jul 10, 2006 1:47 am
    Posts: 8
    Thanks. Thats useful but requires the secodn level cache to be switched on-which I know is very useful. But is there a way to acheive the same result with only the session cache?


    Top
     Profile  
     
     Post subject:
    PostPosted: Sun Dec 03, 2006 3:19 am 
    Senior
    Senior

    Joined: Tue Aug 23, 2005 8:52 am
    Posts: 181
    Havent tried that but can you just do the mutable="false" and try. Hibernate docs indicate that it does some performance optimizations if the mutable attribute is set to false.


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

    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.