-->
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.  [ 2 posts ] 
Author Message
 Post subject: Object not persisting
PostPosted: Mon Feb 07, 2005 6:59 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
Hi

I have hibernate making all the right noises in persisting my object, I am running a junit test. But it is not persisting the object, so I added some transactional properties around my bean using the org.springframework.orm.hibernate.HibernateTransactionManager and using a 'Target' but I cannot bind to the Target, and if I bind to the offenceDAO, it does not persist...

My DAO is a direct implementation class, I have no interface on it, but I am not aware this should make a difference...

My thinking is that I have not setup the transaction bean(s) correctly, or am using the wrong combination with Oracle 9i...

Can anyone shed any light on the matter?

2.1.7


<?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>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.ocado.tracker.offences.pojo.Offence"
table="OFFENCES"
schema="trkdba"
>

<id
name="offenceUuid"
type="java.lang.Long"
column="OFFENCE_UUID"
>
<meta attribute="use-in-equals">true</meta>
<generator class="sequence">
<param name="sequence">OFFENCES_SEQ</param>
</generator>
</id>

<property
name="status"
type="java.lang.String"
column="STATUS"
not-null="true"
length="20"
/>
<property
name="authority"
type="java.lang.String"
column="AUTHORITY"
length="20"
/>
<property
name="ticketNumber"
type="java.lang.String"
column="TICKET_NUMBER"
length="20"
/>
<property
name="offence"
type="java.lang.String"
column="OFFENCE"
length="20"
/>
<property
name="employeeUuid"
type="java.lang.String"
column="EMPLOYEE_UUID"
length="20"
/>
<property
name="datetimeOfOffence"
type="java.sql.Timestamp"
column="DATETIME_OF_OFFENCE"
length="7"
/>
<property
name="datetimeOfTicket"
type="java.sql.Timestamp"
column="DATETIME_OF_TICKET"
length="7"
/>
<property
name="parkingAttendant"
type="java.lang.String"
column="PARKING_ATTENDANT"
length="20"
/>
<property
name="site"
type="java.math.BigDecimal"
column="SITE"
length="22"
/>
<property
name="fleetUuid"
type="java.lang.String"
column="FLEET_UUID"
length="20"
/>
<property
name="locOfOffence"
type="java.lang.String"
column="LOC_OF_OFFENCE"
length="30"
/>
<property
name="postcode"
type="java.lang.String"
column="POSTCODE"
length="8"
/>
<property
name="creditcardAuth"
type="java.lang.String"
column="CREDITCARD_AUTH"
length="10"
/>
<property
name="fine"
type="java.math.BigDecimal"
column="FINE"
length="22"
/>
<property
name="amountPaid"
type="java.math.BigDecimal"
column="AMOUNT_PAID"
length="22"
/>
<property
name="orderNumber"
type="java.lang.String"
column="ORDER_NUMBER"
length="10"
/>
<property
name="routeId"
type="java.lang.String"
column="ROUTE_ID"
length="10"
/>
<property
name="enteredBy"
type="java.lang.String"
column="ENTERED_BY"
not-null="true"
length="50"
/>
<property
name="assignedTo"
type="java.lang.String"
column="ASSIGNED_TO"
length="50"
/>
<property
name="lastModified"
type="java.sql.Timestamp"
column="LAST_MODIFIED"
not-null="true"
length="7"
/>
<property
name="lastModifiedBy"
type="java.lang.String"
column="LAST_MODIFIED_BY"
not-null="true"
length="50"
/>
<property
name="creationDate"
type="java.sql.Timestamp"
column="CREATION_DATE"
not-null="true"
length="7"
/>

<!-- Associations -->


</class>
</hibernate-mapping>





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

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<!-- DataSource -->

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:auser/password@ahost:1521:aschema</value>
</property>
<property name="username">
<value>auser</value>
</property>
<property name="password">
<value>apassword</value>
</property>
</bean>



<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="mappingResources">
<list>
<value>com/ocado/tracker/offences/pojo/Offence.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.max_fetch_depth">2</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.Provider</prop>
</props>
</property>
</bean>

<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<bean id="offenceDAOTarget" class="com.ocado.tracker.offences.dao.OffencesDAO">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<bean id="offenceDAO"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="target"><ref local="offenceDAOTarget"/></property>

<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>



Full stack trace of any exception that occurs:

07-02-05 10:30:56:632 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Bean with name 'offenceDAO' is a factory bean

Name and version of the database you are using:

Oracle 9i

The generated SQL (show_sql=true):

Does not get that far..

Debug level Hibernate log excerpt:


07-02-05 10:30:56:507 - {DEBUG} interceptor.NameMatchTransactionAttributeSource
Thread [main]; Adding transactional method [save*] with attribute [PROPAGATION_
REQUIRED,ISOLATION_DEFAULT]
07-02-05 10:30:56:507 - {DEBUG} beans.BeanWrapperImpl Thread [main]; Invoked wr
ite method [public void org.springframework.transaction.interceptor.TransactionP
roxyFactoryBean.setTransactionAttributes(java.util.Properties)] with value of ty
pe [java.util.Properties]
07-02-05 10:30:56:507 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Invoking BeanPostProcessors before initialization of bean 'offenceDAO'
07-02-05 10:30:56:507 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Invoking afterPropertiesSet() on bean with beanName 'offenceDAO'
07-02-05 10:30:56:523 - {DEBUG} core.CollectionFactory Thread [main]; Creating
java.util.IdentityHashMap
07-02-05 10:30:56:538 - {DEBUG} framework.ProxyFactory Thread [main]; Added new
aspect interface: org.springframework.beans.factory.InitializingBean
07-02-05 10:30:56:538 - {DEBUG} framework.JdkDynamicAopProxy Thread [main]; Cre
ating JDK dynamic proxy for [com.ocado.tracker.offences.dao.OffencesDAO]
07-02-05 10:30:56:554 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Invoking BeanPostProcessors after initialization of bean 'offenceDAO'
07-02-05 10:30:56:554 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Calling code asked for FactoryBean instance for name 'offenceDAO'
07-02-05 10:30:56:554 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Returning cached instance of singleton bean 'offenceDAO'
07-02-05 10:30:56:554 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Bean with name 'offenceDAO' is a factory bean
07-02-05 10:30:56:570 - {DEBUG} support.ClassPathXmlApplicationContext Thread [m
ain]; Publishing event in context [org.springframework.context.support.ClassPat
hXmlApplicationContext;hashCode=7043360]: org.springframework.context.event.Cont
extRefreshedEvent[source=org.springframework.context.support.ClassPathXmlApplica
tionContext: display name [org.springframework.context.support.ClassPathXmlAppli
cationContext;hashCode=7043360]; startup date [Mon Feb 07 10:30:54 GMT 2005]; ro
ot of context hierarchy]
07-02-05 10:30:56:570 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Returning cached instance of singleton bean 'sessionFactory'
07-02-05 10:30:56:570 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Bean with name 'sessionFactory' is a factory bean
07-02-05 10:30:56:570 - {DEBUG} hibernate.SessionFactoryUtils Thread [main]; Op
ening Hibernate session
07-02-05 10:30:56:632 - {DEBUG} impl.SessionImpl Thread [main]; opened session
07-02-05 10:30:56:632 - {DEBUG} support.TransactionSynchronizationManager Thread
[main]; Bound value [org.springframework.orm.hibernate.SessionHolder@691dee] f
or key [net.sf.hibernate.impl.SessionFactoryImpl@29c58e] to thread [main]
07-02-05 10:30:56:632 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Returning cached instance of singleton bean 'offenceDAO'
07-02-05 10:30:56:632 - {DEBUG} support.DefaultListableBeanFactory Thread [main]
; Bean with name 'offenceDAO' is a factory bean


Top
 Profile  
 
 Post subject: Fixed problem
PostPosted: Mon Feb 07, 2005 7:14 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
It seems it DOES need an interface to the DAO object for this to work!

So with

public interface OffencesDAO {

public void loadSomething();
}

public class OffencesDAOHibernate {

public void loadSomething() {


}
}

and defining OffencesDAOHibernate it does work...


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