Hi,
I almost have my first example working-- I have a DAO, my POJO and mapping file and code that uses the DAO. I see that everything works as far as creating objets and storing them in the hibernate session. However when I shut down my DB, none of the data in the hibernate session is actually being saved, when I restart the DB again! Do I need to call session.close or sessionfactory.close myself-- I thought maybe Spring takes care of this?
Thanks, Jason
---
-------------Code:<beans> <!-- Datasource that works in any application server You could easily use J2EE data source instead if this were running inside of a J2EE container. --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"><value>org.hsqldb.jdbcDriver</value></property> <property name="url"><value>jdbc:hsqldb:/Users/novotny/Jakarta/jakarta-tomcat-5.0.28/webapps/gridsphere/WEB-INF/CustomPortal/database/gridsphere</value></property> <property name="username"><value>sa</value></property> <property name="password"><value></value></property> </bean> <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="dataSource"><ref local="dataSource"/></property> <!-- Must references all OR mapping files. --> <property name="mappingDirectoryLocations"> <list> <value>WEB-INF/persistence</value> </list> </property> <!-- Set the type of database; changing this one property will port this to Oracle, MS SQL etc. --> <property name="hibernateProperties"> <props> <prop key="hibernate.c3p0.max_size">10</prop> <prop key="hibernate.c3p0.min_size">2</prop> <prop key="hibernate.c3p0.timeout">5000</prop> <prop key="hibernate.c3p0.max_statements">100</prop> <prop key="hibernate.c3p0.idle_test_period">3000</prop> <prop key="hibernate.c3p0.acquire_increment">2</prop> <prop key="hibernate.dialect">net.sf.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.query.substitutions">true 1, false 0, yes 'Y', no 'N'</prop> </props> </property> </bean> <!-- Pass the session factory to our UserDAO --> <bean id="trackerDao" class="org.gridlab.gridsphere.services.core.tracker.impl.TrackerDaoImpl"> <property name="sessionFactory" ref="sessionFactory"/> </bean> </beans>
My TrackerDao class:
----Code:public class TrackerDaoImpl extends HibernateDaoSupport implements TrackerDao { private PortletLog log = SportletLog.getInstance(TrackerServiceImpl.class); /** * Persists a tracking label to the GridSphere database * * @param label a label used in identifying the action invoked * @param userAgent the user agent string provided by the web browser * @param userName the user name */ public void trackURL(String label, String userAgent, String userName) { TrackerInfo info = new TrackerInfo(); info.setLabel(label); info.setDate(Calendar.getInstance().getTime().getTime()); info.setUserAgent(userAgent); info.setUserName(userName); this.getHibernateTemplate().saveOrUpdate(info); } public List getTrackingActions() { return this.getHibernateTemplate().find("from " + TrackerAction.class.getName() + " as trackeraction"); } public TrackerAction getTrackingAction(String actionName) { List actions = this.getHibernateTemplate().find("from " + TrackerAction.class.getName() + " as trackeraction where trackeraction.Action=\'" + actionName + "'"); if ((actions != null) && (!actions.isEmpty())) { return (TrackerAction)actions.get(0); } return null; } public void addTrackingAction(TrackerAction action) { this.getHibernateTemplate().saveOrUpdate(action); } public void removeTrackingAction(String action) { this.getHibernateTemplate().delete(action); } public void clearTrackingActions() { this.getHibernateTemplate().delete("from " + TrackerAction.class.getName() + " as trackeraction "); } /** * Return a list of the available labels * * @return a list of the available labels */ public List getTrackingLabels() { return this.getHibernateTemplate().find("select tracker.Label from " + TrackerInfo.class.getName() + " as tracker"); } /** * Return a list of TrackerInfo objects for the provided label * * @return a list of TrackerInfo objects for the provided label */ public List getTrackingInfoByLabel(String label) { return this.getHibernateTemplate().find("from " + TrackerInfo.class.getName() + " as tracker where tracker.Label='" + label + "'"); } public boolean hasTrackingAction(String actionName) { TrackerAction ta = getTrackingAction(actionName); return ((ta != null) && (ta.isEnabled())); } }
TrackerInfo.hbm.xml
-----
------Code:<hibernate-mapping> <class name="org.gridlab.gridsphere.services.core.tracker.impl.TrackerInfo" table="tracker_info" > <id name="oid" column="gsoid" type="java.lang.String" length="32" > <generator class="uuid.hex"/> </id> <property name="Label" type="string" column="label"/> <property name="Date" type="long" column="trackerdate"/> <property name="UserAgent" type="string" column="useragent"/> <property name="UserName" type="string" column="username"/> </class> <class name="org.gridlab.gridsphere.services.core.tracker.impl.TrackerAction" table="tracker_action" > <id name="oid" column="gsoid" type="java.lang.String" length="32" > <generator class="uuid.hex"/> </id> <property name="Enabled" type="boolean" column="enabled"/> <property name="Action" type="string" column="action"/> </class> </hibernate-mapping>


Reply With Quote
