Hi,I have a simple example the start main is this:
import it.Product;
import org.hibernate.*; import org.hibernate.cfg.*; import org.hibernate.engine.spi.SessionFactoryImplementor; public class ClientForSave { public static void main(String[] args) { Configuration cfg = new Configuration(); cfg.configure("Util/hibernate.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); SessionFactoryImplementor sfi = (SessionFactoryImplementor)factory; String name = sfi.getSettings().getDefaultSchemaName(); System.out.println(name); Product p=new Product(); p.setProductId(105); p.setProName("iPhone"); p.setPrice(2510); Transaction tx = session.beginTransaction(); session.save(p); System.out.println("Object saved successfully.....!!"); tx.commit(); session.close(); factory.close(); }
when i run the applciation the result is this,'
ott 24, 2013 10:38:59 PM org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} ott 24, 2013 10:38:59 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.1.4.Final} ott 24, 2013 10:38:59 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found ott 24, 2013 10:38:59 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist ott 24, 2013 10:38:59 PM org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: Util/hibernate.cfg.xml ott 24, 2013 10:38:59 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: Util/hibernate.cfg.xml ott 24, 2013 10:38:59 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! ott 24, 2013 10:38:59 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: it/Product.hbm.xml ott 24, 2013 10:38:59 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! ott 24, 2013 10:38:59 PM org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: ott 24, 2013 10:38:59 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) ott 24, 2013 10:39:00 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 ott 24, 2013 10:39:00 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: false ott 24, 2013 10:39:00 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:xe] ott 24, 2013 10:39:00 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: {user=SYSTEM, password=****} ott 24, 2013 10:39:00 PM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect ott 24, 2013 10:39:00 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000399: Using default transaction strategy (direct JDBC transactions) ott 24, 2013 10:39:00 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory ott 24, 2013 10:39:00 PM org.hibernate.internal.SessionFactoryRegistry addSessionFactory WARN: HHH000277: Could not bind factory to JNDI org.hibernate.service.jndi.JndiException: Error parsing JNDI name [] at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92) at org.hibernate.service.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:108) at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:89) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:481) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782) at Util.ClientForSave.main(ClientForSave.java:18) Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getNameParser(Unknown Source) at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86) ... 6 more
ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: SYSTEM.PRODUCT ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [price, productid, proname] ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [] ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [sys_c007080] ott 24, 2013 10:39:00 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete null Object saved successfully.....!! Hibernate: insert into PRODUCT (PRONAME, PRICE, PRODUCTID) values (?, ?, ?) ott 24, 2013 10:39:01 PM org.hibernate.internal.SessionFactoryRegistry removeSessionFactory WARN: HHH000374: Could not unbind factory from JNDI org.hibernate.service.jndi.JndiException: Error parsing JNDI name [] at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92) at org.hibernate.service.jndi.internal.JndiServiceImpl.unbind(JndiServiceImpl.java:176) at org.hibernate.internal.SessionFactoryRegistry.removeSessionFactory(SessionFactoryRegistry.java:117) at org.hibernate.internal.SessionFactoryImpl.close(SessionFactoryImpl.java:1449) at Util.ClientForSave.main(ClientForSave.java:34) Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getNameParser(Unknown Source) at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86) ... 4 more
ott 24, 2013 10:39:01 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop INFO: HHH000030: Cleaning up connection pool [jdbc:oracle:thin:@localhost:1521:xe]
There is error?The application insert the element???Infact when i run again with the sample date,the result is this....So, in theory, should have made the inclusion?I downloaded from this site http://www.oracle.com/technetwork/products/express-edition/downloads/index.html
oracle g11, but when i open the application i not find the table,where is put the table?? Should I use the command line or something?? ott 24, 2013 10:39:35 PM org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} ott 24, 2013 10:39:35 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.1.4.Final} ott 24, 2013 10:39:35 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found ott 24, 2013 10:39:35 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist ott 24, 2013 10:39:35 PM org.hibernate.cfg.Configuration configure INFO: HHH000043: Configuring from resource: Util/hibernate.cfg.xml ott 24, 2013 10:39:35 PM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: HHH000040: Configuration resource: Util/hibernate.cfg.xml ott 24, 2013 10:39:35 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! ott 24, 2013 10:39:35 PM org.hibernate.cfg.Configuration addResource INFO: HHH000221: Reading mappings from resource: it/Product.hbm.xml ott 24, 2013 10:39:35 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! ott 24, 2013 10:39:35 PM org.hibernate.cfg.Configuration doConfigure INFO: HHH000041: Configured SessionFactory: ott 24, 2013 10:39:35 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) ott 24, 2013 10:39:36 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 ott 24, 2013 10:39:36 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: false ott 24, 2013 10:39:36 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:xe] ott 24, 2013 10:39:36 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: {user=SYSTEM, password=****} ott 24, 2013 10:39:36 PM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect ott 24, 2013 10:39:36 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000399: Using default transaction strategy (direct JDBC transactions) ott 24, 2013 10:39:36 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory ott 24, 2013 10:39:36 PM org.hibernate.internal.SessionFactoryRegistry addSessionFactory WARN: HHH000277: Could not bind factory to JNDI org.hibernate.service.jndi.JndiException: Error parsing JNDI name [] at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92) at org.hibernate.service.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:108) at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:89) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:481) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782) at Util.ClientForSave.main(ClientForSave.java:18) Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getNameParser(Unknown Source) at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86) ... 6 more
ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: SYSTEM.PRODUCT ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [price, productid, proname] ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [] ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [sys_c007080] ott 24, 2013 10:39:36 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete null Object saved successfully.....!! Hibernate: insert into PRODUCT (PRONAME, PRICE, PRODUCTID) values (?, ?, ?) ott 24, 2013 10:39:37 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 1, SQLState: 23000 ott 24, 2013 10:39:37 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: ORA-00001: unique constraint (SYSTEM.SYS_C007080) violated
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: ORA-00001: unique constraint (SYSTEM.SYS_C007080) violated
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:74) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129) at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) at com.sun.proxy.$Proxy5.executeUpdate(Unknown Source) at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2859) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3300) at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1214) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403) at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101) at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175) at Util.ClientForSave.main(ClientForSave.java:32) Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (SYSTEM.SYS_C007080) violated
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1010) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576) at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657) at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 16 more
|