I am using Hibernate 4 with Postgresql Database. The selection queries executing well, but when it comes to updating queries (Insertion) is not working at all.
The logs doesn't say anything about errors , everything seems ok and committed. Am trying to save an object using Dao layer :
public void add(Role role) {
sessionFactory.openSession().save(role);
}
Service layer :
@Transactional
public void addNewRole(Role role) {
roleDao.add(role);
}
Role object is mapped , sessionfactory is injected without any problem. And here is what the logs says :
2014-09-28 10:44:52 DEBUG HibernateTransactionManager:367 - Creating new transaction with name [com.x.y.base.services.imp.RoleServiceImp.addNewRole]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
2014-09-28 10:44:52 DEBUG HibernateTransactionManager:420 - Opened new Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=org.hibernate.engine.spi.ExecutableList@66f9104a updates=org.hibernate.engine.spi.ExecutableList@699c9f16 deletions=org.hibernate.engine.spi.ExecutableList@29909385 orphanRemovals=org.hibernate.engine.spi.ExecutableList@52c51614 collectionCreations=org.hibernate.engine.spi.ExecutableList@92ca580 collectionRemovals=org.hibernate.engine.spi.ExecutableList@52257b34 collectionUpdates=org.hibernate.engine.spi.ExecutableList@1abbbd0e collectionQueuedOps=org.hibernate.engine.spi.ExecutableList@1b78efd8 unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])] for Hibernate transaction
2014-09-28 10:44:52 DEBUG HibernateTransactionManager:430 - Preparing JDBC Connection of Hibernate Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=org.hibernate.engine.spi.ExecutableList@66f9104a updates=org.hibernate.engine.spi.ExecutableList@699c9f16 deletions=org.hibernate.engine.spi.ExecutableList@29909385 orphanRemovals=org.hibernate.engine.spi.ExecutableList@52c51614 collectionCreations=org.hibernate.engine.spi.ExecutableList@92ca580 collectionRemovals=org.hibernate.engine.spi.ExecutableList@52257b34 collectionUpdates=org.hibernate.engine.spi.ExecutableList@1abbbd0e collectionQueuedOps=org.hibernate.engine.spi.ExecutableList@1b78efd8 unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])]
2014-09-28 10:44:52 DEBUG DriverManagerDataSource:142 - Creating new JDBC DriverManager Connection to [jdbc:postgresql://localhost:5432/moe]
2014-09-28 10:44:52 DEBUG HibernateTransactionManager:491 - Exposing Hibernate transaction as JDBC transaction [org.postgresql.jdbc4.Jdbc4Connection@11fb24d3]
2014-09-28 10:44:52 DEBUG HibernateTransactionManager:755 - Initiating transaction commit
2014-09-28 10:44:52 DEBUG HibernateTransactionManager:554 - Committing Hibernate transaction on Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=org.hibernate.engine.spi.ExecutableList@66f9104a updates=org.hibernate.engine.spi.ExecutableList@699c9f16 deletions=org.hibernate.engine.spi.ExecutableList@29909385 orphanRemovals=org.hibernate.engine.spi.ExecutableList@52c51614 collectionCreations=org.hibernate.engine.spi.ExecutableList@92ca580 collectionRemovals=org.hibernate.engine.spi.ExecutableList@52257b34 collectionUpdates=org.hibernate.engine.spi.ExecutableList@1abbbd0e collectionQueuedOps=org.hibernate.engine.spi.ExecutableList@1b78efd8 unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])]
2014-09-28 10:44:52 DEBUG HibernateTransactionManager:636 - Closing Hibernate Session [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=org.hibernate.engine.spi.ExecutableList@66f9104a updates=org.hibernate.engine.spi.ExecutableList@699c9f16 deletions=org.hibernate.engine.spi.ExecutableList@29909385 orphanRemovals=org.hibernate.engine.spi.ExecutableList@52c51614 collectionCreations=org.hibernate.engine.spi.ExecutableList@92ca580 collectionRemovals=org.hibernate.engine.spi.ExecutableList@52257b34 collectionUpdates=org.hibernate.engine.spi.ExecutableList@1abbbd0e collectionQueuedOps=org.hibernate.engine.spi.ExecutableList@1b78efd8 unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])] after transaction
spring-db.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:aop="http://ift.tt/OpNdV1"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:tx="http://ift.tt/OGfeU2"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/1jdM0fG">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:properties/db.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>mapping/User.hbm.xml</value>
<value>mapping/Role.hbm.xml</value>
<value>mapping/Permission.hbm.xml</value>
<value>mapping/Representation.hbm.xml</value>
<value>mapping/Right.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.conntection.autocommit">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Test app :
public static void main(String[] args) {
ApplicationContext cx = new ClassPathXmlApplicationContext("spring/spring-all.xml");
RoleService roleService = (RoleService) cx.getBean("roleService");
Role role = new Role();
role.setCode("TEST");
role.setName("Test");
role.setDescription("Test Role");
roleService.addNewRole(role);
}
The object is not saved in the physical database at all ? I checked the privileges of database user , but it seems have full super access to all operations !
What could be the reason ?
No comments:
Post a Comment