-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate / Spring / DAO
PostPosted: Sat May 01, 2004 2:59 pm 
Newbie

Joined: Thu Mar 11, 2004 11:20 pm
Posts: 9
i encounter a probelm when using hibernate + spring framework.
there's no exception issued when running the program (in inserting data into database). yet there's no data inserted after "select * from table_name" from sql*plus (oracle database 10.x)
env : hibernate 2.1.x; spring framework 1.0.1; j2sdk1.4.2_03; ant-1.6.1; oracle 10.x
below A.) are conf file:
and B.) is DAO interface and its impl (parts of) content:
what might causes such problem?
i appreaciate any suggestions,
sincerely.
thank you very much

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


<beans>

<!-- ========================= GENERAL DEFINITIONS ========================= -->

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->


<!-- Message source for this context, loaded from localized "messages_xx" files -->


<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename"><value>messages</value></property>
</bean>


<!-- ========================= RESOURCE DEFINITIONS ========================= -->

<!-- Local DataSource that works in any environment -->

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- org.apache.commons.dbcp.BasicDataSource" -->
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@localhost:1521:orcl</value></property>
<property name="username"><value>username</value></property>
<property name="password"><value>password</value></property>
</bean>
<!-- JNDI DataSource for J2EE environments -->


<!-- Hibernate SessionFactory -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<value>mapping.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>

<prop key="hibernate.show_sql">true</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>

<!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
<!--
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
-->


<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->

<!-- Transactional proxy for the Petclinic primary business object -->
<bean id="DAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="target"><ref local="targetDAO"/></property>
<property name="transactionAttributes">
<props>

<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="store*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<!-- Petclinic primary business object: Hibernate implementation -->
<bean id="targetDAO" class="dao.DAOImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>


</beans>

============
B.)
public interface DAO {
// ...: BEG
public void storeCBean(CBean entity) throws DataAccessException;
public List findAllCBean() throws DataAccessException;
public List checkCBeanByName(String name) throws DataAccessException;
// ...: END
}

public class DAOImpl extends HibernateDaoSupport implements DAO {
// ...: BEG
public void storeCBean(CBean entity) throws DataAccessException{
getHibernateTemplate().saveOrUpdate(entity);

}
public List findAllCBean() throws DataAccessException {
return getHibernateTemplate().find(
"from cBean in class CBean order by CBean.productName");
}
public List checkCBeanByName(String name)
throws DataAccessException {
return getHibernateTemplate().find(
"from cBean in class CBean where cBean.productName = ?",
name,
Hibernate.STRING);
}
// ...: END
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 6:24 am 
Senior
Senior

Joined: Wed Aug 27, 2003 6:04 am
Posts: 161
Location: Linz, Austria
Basically, your code looks fine. How are you invoking it? Fetching the "DAO" bean and calling the "storeCBean" method?

Try to find out whether Hibernate attempts to flush, and whether it actually issues any SQL statements to the database: Turn Hibernate's logging of SQL statements on, and raise the general logging level at least to INFO.

Juergen


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 3:38 am 
Newbie

Joined: Thu Mar 11, 2004 11:20 pm
Posts: 9
jhoeller wrote:
Basically, your code looks fine. How are you invoking it? Fetching the "DAO" bean and calling the "storeCBean" method?

Try to find out whether Hibernate attempts to flush, and whether it actually issues any SQL statements to the database: Turn Hibernate's logging of SQL statements on, and raise the general logging level at least to INFO.

Juergen


Hi, I've solved my problem. It results from storeCBean() method
of the DAOImpl where I want to insert data into database. The implementation code I use is saveOrUpdate(); which seemly would not work because originally there's no data (the same as in the test class) in the database. Therefore, I change method saveOrUpdate() to save(). Finally it gets to work. Simply I do not know the reason why. Would anyone be kindly to exaplain it or tell me where is resource / doc talking about this? I'm new to hibernate and appreciate any suggestions, sincerely.
Arsene


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 4:26 am 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
It sounds like you haven't set the unsaved-value of your ID column - if this isn't set, then Hibernate will assume that all objects need to be updated when you call the saveOrUpdate() method.

Check out http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-id for more information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.