-->
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.  [ 3 posts ] 
Author Message
 Post subject: How do I generate properties on load?
PostPosted: Tue Mar 21, 2006 4:39 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 10:29 am
Posts: 21
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
2.1.8

Mapping documents:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.skillsoft.ilt.beans">
<class name="Session" table="iltSession">
<id name="ID" column="ID" unsaved-value="0">
<generator class="native"/>
</id>
<property name="number" column="number"/>
<property name="notes" column="notes"/>
<property name="timeZoneID" column="tzid"/>
<property name="statusCode" column="status"/>
<property name="capacity" column="capacity"/>
<property name="closingDays" column="closingDays"/>
<property name="instructorPrivileged" column="instructorPrivileged"/>
<property name="sessionApprovalRequired" column="sessionApprovalRequired"/>
<property name="approvalRequired" column="approvalRequired"/>
<property name="enrolled"/>
<property name="waiting"/>
<property name="percentFull"/>
<many-to-one name="instructor" class="User" column="instructor"/>
<many-to-one name="ownedBy" class="User" column="sessionOwner"/>
<many-to-one name="sessionApprover" class="User" column="sessionApprover"/>
<many-to-one name="course" class="Course" column="course"/>
<many-to-one name="facility" class="Facility" column="facility"/>
<many-to-one name="classroom" class="Classroom" column="classroom"/>
<many-to-one name="owner" column="owner" class="Contact"/>
<!-- dialogue -->
<one-to-one name="dialogInfo" class="DialogSession" cascade="all" />

<!-- bag => Collection, unordered, allows duplicates -->
<bag
name="roster"
table="iltRegistration"
inverse="true"
cascade="all-delete-orphan"
lazy="true"
outer-join="false"
batch-size="100">
<key column="session"/>
<one-to-many class="Registration"/>
</bag>
<!-- bag => Collection, unordered, allows duplicates -->
<bag
name="schedule"
table="iltScheduleinfo"
inverse="true"
order-by="startTime"
cascade="all-delete-orphan"
lazy="false"
outer-join="false"
batch-size="100">
<key column="session"/>
<one-to-many class="Schedule"/>
</bag>
<!-- bag => Collection, unordered, allows duplicates -->
<bag
name="attrValues"
table="iltExtAttrSession"
inverse="true"
lazy="false"
cascade="all-delete-orphan"
outer-join="false"
batch-size="100">
<key column="sessionid"/>
<many-to-many class="ExtAttrSession" column="valueid"/>
</bag>
</class>
</hibernate-mapping>

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

Full stack trace of any exception that occurs:

Name and version of the database you are using:

SQL Server 2000 SP4

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I would like to generate the data needed for the Session properties enrolled, waiting, and percentFull when I load the data. I know the SQL I want to run, but I'm uncertain how to configure this. I see there is an option to generate properties on SQL insert or update. I would really like to know how to generate these on load. I'm referencing data in another table (iltRegistration) to generate this data.

(SELECT COUNT(iltRegistration.ID)
FROM iltRegistration
WHERE iltRegistration.session = iltSession.ID
AND iltRegistration.status != 400 AND iltRegistration.status != 300) enrolled

(SELECT COUNT(iltRegistration.ID)
FROM iltRegistration
WHERE iltRegistration.session = iltSession.ID
AND iltRegistration.status = 400) waiting

percentFull =
CASE iltSession.capacity
WHEN 0 THEN 0.0
ELSE
((CAST(enrolled AS FLOAT) + CAST(waiting AS FLOAT)) / CAST(iltSession.capacity AS FLOAT))
END


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 4:56 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
check out: Chapter 12. Interceptors and events
in reference.pdf

http://www.hibernate.org/hib_docs/v3/reference/en/pdf/hibernate_reference.pdf

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 21, 2006 5:02 pm 
Beginner
Beginner

Joined: Fri Oct 15, 2004 10:29 am
Posts: 21
I was hoping to do this in the mapping configuration rather than code, but this might be good enough if the other properties are available in the onLoad method.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.