File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes The user must supply a JDBC connection with Spring 3.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "The user must supply a JDBC connection with Spring 3.1" Watch "The user must supply a JDBC connection with Spring 3.1" New topic
Author

The user must supply a JDBC connection with Spring 3.1

Abhishek Uppala
Greenhorn

Joined: May 27, 2009
Posts: 10

Hi,

I am developing a project using Spring 3.2.1 and Hibernate 3.6.0. I have configured my datasource and LocalSessionFactoryBean as below:

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="root" />
<property name="password" value="abcd" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.c20.domain.Customer</value>
<value>com.c20.domain.Address</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

Now I have my data access implementation as below

public class GenericDaoImpl<T, K extends Serializable> extends
HibernateTemplate implements GenericDao<T, K> {

public GenericDaoImpl(SessionFactory sessionFactory) {
super(sessionFactory);
}

public final Class getType() {
ParameterizedType parameterizedType = (ParameterizedType) getClass()
.getGenericSuperclass();
return (Class) parameterizedType.getActualTypeArguments()[0];
}

@Override
public T get(Serializable identifier) {
return (T) getSession().get(getType(), identifier);
}

@Override
public K saveObject(T object) {
return (K) getSession().save(object);
}

}

When my service class invokes saveObject, I am getting the below error.

java.lang.UnsupportedOperationException: The user must supply a JDBC connection
org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:54)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2327)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2834)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)

I have looked around the net but was not able to resolve the issue. Kindly suggest on getting the above stated issue resolved

Thanks in advance

Thanks
Abhishek Uppala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The user must supply a JDBC connection with Spring 3.1