Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2012
    Messaggi
    147

    problema utilizzo Hibernate

    Ciao,ho cercato di realizzare un semplice progetto hibernate ho creato una classe Product con i metodi set e get e poi la relativa classe hbm,in seguito file cfg che è il seguente

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    <session-factory name="">
    <!-- Related to the connection START -->
    <property name="connection.driver_class">oracle.jdbc.driver. OracleDriver</property>
    <property name="connection.url">jdbcracle:thin:@localhost:1521:xe</property>
    <property name="connection.user">SYSTEM</property>
    <property name="connection.password">puffo</property>
    <!-- Related to the connection END
    Related to hibernate properties START -->
    <property name="show_sql">true</property>
    <property name="dialet">org.hibernate.dialect.OracleDialect</property>

    <property name="hbm2ddl.auto">update</property>
    <mapping resource="it/Product.hbm.xml"/>





    <!-- Related to hibernate properties END
    Related to mapping START
    Related to the mapping END -->
    </session-factory>

    PRIMA DOMANDA DOVE TROVO IL RISULTATO DEL INSERIMENTO???PERCHE HO SCARICATO ORACLE ENTERPRISE 11G E SE AVVIO L'APP E PROVO A NAVIGARE NEL TOOL GRAFICO NON LO VEDO?DEVO USARE RIGA DI COMANDO??PERCHE TOOL GRAFICO USA PORTA 8080 MA NON SO DITEMI COME FATE VOI????



    e il file finale
    mport 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();
    }

    }

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2012
    Messaggi
    147
    MI DA QUESTO FILE DI LOG

    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.Dr iverManagerConnectionProviderImpl 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.Dr iverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 20
    ott 24, 2013 10:39:00 PM org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: false
    ott 24, 2013 10:39:00 PM org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbcracle:thin:@localhost:1521:xe]
    ott 24, 2013 10:39:00 PM org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl 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.Transact ionFactoryInitiator initiateService
    INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
    ott 24, 2013 10:39:00 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorF actory <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.JndiServiceImp l.parseName(JndiServiceImpl.java:92)
    at org.hibernate.service.jndi.internal.JndiServiceImp l.bind(JndiServiceImpl.java:108)
    at org.hibernate.internal.SessionFactoryRegistry.addS essionFactory(SessionFactoryRegistry.java:89)
    at org.hibernate.internal.SessionFactoryImpl.<init>(S essionFactoryImpl.java:481)
    at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1744)
    at org.hibernate.cfg.Configuration.buildSessionFactor y(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(U nknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unkn own Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx (Unknown Source)
    at javax.naming.InitialContext.getNameParser(Unknown Source)
    at org.hibernate.service.jndi.internal.JndiServiceImp l.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.JndiServiceImp l.parseName(JndiServiceImpl.java:92)
    at org.hibernate.service.jndi.internal.JndiServiceImp l.unbind(JndiServiceImpl.java:176)
    at org.hibernate.internal.SessionFactoryRegistry.remo veSessionFactory(SessionFactoryRegistry.java:117)
    at org.hibernate.internal.SessionFactoryImpl.close(Se ssionFactoryImpl.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(U nknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unkn own Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx (Unknown Source)
    at javax.naming.InitialContext.getNameParser(Unknown Source)
    at org.hibernate.service.jndi.internal.JndiServiceImp l.parseName(JndiServiceImpl.java:86)
    ... 4 more

    ott 24, 2013 10:39:01 PM org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl stop
    INFO: HHH000030: Cleaning up connection pool [jdbcracle:thin:@localhost:1521:xe]


    SEMBRA ANDARE,MA NON SO..PERO SE PROVO A RIFARE LO STESSO INSERIMENTO MI DICE CHE DEVO CAMBIARE I DATI PERCHE ID DEVE ESSERE UNIVOCO,QUINDI IN TEORIA E STATO INSERITO??MA DOVE VISTO CHE NON LO VEDO NELL TOOL GRAFICO..QUI IL TENTATIVO DI STESSO INSERIMENTO


    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??


  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2012
    Messaggi
    147
    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.Dr iverManagerConnectionProviderImpl 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.Dr iverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 20
    ott 24, 2013 10:39:36 PM org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: false
    ott 24, 2013 10:39:36 PM org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbcracle:thin:@localhost:1521:xe]
    ott 24, 2013 10:39:36 PM org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl 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.Transact ionFactoryInitiator initiateService
    INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
    ott 24, 2013 10:39:36 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorF actory <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.JndiServiceImp l.parseName(JndiServiceImpl.java:92)
    at org.hibernate.service.jndi.internal.JndiServiceImp l.bind(JndiServiceImpl.java:108)
    at org.hibernate.internal.SessionFactoryRegistry.addS essionFactory(SessionFactoryRegistry.java:89)
    at org.hibernate.internal.SessionFactoryImpl.<init>(S essionFactoryImpl.java:481)
    at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1744)
    at org.hibernate.cfg.Configuration.buildSessionFactor y(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(U nknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unkn own Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx (Unknown Source)
    at javax.naming.InitialContext.getNameParser(Unknown Source)
    at org.hibernate.service.jndi.internal.JndiServiceImp l.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>

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2012
    Messaggi
    147
    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.ConstraintViolationExcepti on: ORA-00001: unique constraint (SYSTEM.SYS_C007080) violated

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2012
    Messaggi
    147
    Problema risolto

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.