aspose file tools*
The moose likes Object Relational Mapping and the fly likes Not able to update or save a object to database. please help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Not able to update or save a object to database. please help." Watch "Not able to update or save a object to database. please help." New topic
Author

Not able to update or save a object to database. please help.

Anuradha Prasanna
Ranch Hand

Joined: Mar 09, 2006
Posts: 115
Hi,

iam trying to add a "Employee" object to database, but after running the program i dont see any updated rows.
Iam using Oracle 10g.

The following is my "Employee.java" class,



The hibernate.cfg.xml and Employee.hbm.xml files are,





and the console output is,

May 6, 2010 1:27:07 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.0-Final
May 6, 2010 1:27:07 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
May 6, 2010 1:27:07 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
May 6, 2010 1:27:07 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
May 6, 2010 1:27:08 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
May 6, 2010 1:27:08 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
May 6, 2010 1:27:08 AM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : oracle/hibernate/example/Employee.hbm.xml
May 6, 2010 1:27:08 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: oracle.hibernate.example.Employee -> employee
May 6, 2010 1:27:08 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
May 6, 2010 1:27:08 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
May 6, 2010 1:27:08 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
May 6, 2010 1:27:08 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: true
May 6, 2010 1:27:08 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbcracle:thin:hr/hr@localhost:1521/XE
May 6, 2010 1:27:08 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=hr, password=****, autocommit=true}
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 10.2.0.1.0XE
May 6, 2010 1:27:09 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
May 6, 2010 1:27:09 AM org.hibernate.engine.jdbc.JdbcSupportLoader useContextualLobCreation
INFO: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
May 6, 2010 1:27:09 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
May 6, 2010 1:27:09 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
May 6, 2010 1:27:09 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Hibernate: update employee set emp_name=?, dept_name=?, salary=?, email=? where emp_id=? //line a
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
May 6, 2010 1:27:09 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
May 6, 2010 1:27:09 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
May 6, 2010 1:27:10 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Employee details saved Successfully... Great Job!!!
May 6, 2010 1:27:10 AM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
May 6, 2010 1:27:10 AM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbcracle:thin:hr/hr@localhost:1521/XE

i can see the udate query in line a of output.. but still no rows or added or updated.
can anyone please explain why?


SCJP 6.0 90%
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67
According to me;
You should be know schema 'XE' given by you it must exist. and donot fulsh() the session before tra.commit();
Ashish P Gandhi
Greenhorn

Joined: May 25, 2010
Posts: 2
Couple of things to check..
1) As pointed out in earlier post, commit before flush
2) I am not sure of the dialect you are using ( MySQL)
3) Also, if you are using native as the Id generator, then why setting is explicitly through your object.


Regards,
Ashish Gandhi
SCJP 6.0, SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to update or save a object to database. please help.