-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: one-to-many association
PostPosted: Tue May 06, 2008 2:23 pm 
Newbie

Joined: Thu May 01, 2008 4:53 pm
Posts: 11
Hi Every One,
I am using hibernate3.2.6 and oracle 10g and eclipse.I created general Java project in eclipse.I created two classes Event,Event_Organizer for two tables EVENTS and EVENT_ORGANIZERS.
Here is my event.hbm.xml file:

Code:
<?xml version="1.0"?>
  <!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
   <hibernate-mapping>
       <class name="events.Event" table="EVENTS" >
          <id name="eventId" type="java.lang.Integer" column="EVENT_ID" >
                <generator class="increment" />
          </id>
          <property name="eventTitle" type="java.lang.String" column="EVENT_TITLE" length="20" />
          <property name="totalMembers" type="java.lang.Integer" column="TOTAL_MEMBERS" length="-1" />       
          [b]<set name="eventOrganizers" cascade="all">
             <key column="EVENT_ID"/>
             <one-to-many class="events.Event_Organizer"/>
          </set>[/b]
      </class>
   </hibernate-mapping>



and i wrote mappings tags for both *.hbm.xml files in my hibernate.cfg.xml.

Now when i try to run client program.I am getting an exception like below.
Code:
11:56:31,890  INFO Environment:514 - Hibernate 3.2.6
11:56:32,015  INFO Environment:532 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=sun.jdbc.odbc.JdbcOdbcDriver, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=system, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@localhost:1522:XE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
11:56:32,078  INFO Environment:563 - using java.io streams to persist binary types
11:56:32,078  INFO Environment:681 - Bytecode provider name : cglib
11:56:32,093  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
11:56:32,265  INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml
11:56:32,265  INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml
11:56:32,718  INFO Configuration:559 - Reading mappings from resource : events/event.hbm.xml
11:56:32,953  INFO HbmBinder:300 - Mapping class: events.Event -> EVENTS
11:56:32,984  INFO Configuration:559 - Reading mappings from resource : events/event_Organizer.hbm.xml
11:56:33,031  INFO HbmBinder:300 - Mapping class: events.Event_Organizer -> EVENT_ORGANIZERS
11:56:33,046  INFO Configuration:1547 - Configured SessionFactory: null
11:56:33,062  INFO HbmBinder:2382 - Mapping collection: events.Event.eventOrganizers -> EVENT_ORGANIZERS
11:56:33,609  WARN RootClass:210 - composite-id class does not override equals(): events.Event_Organizer
11:56:33,609  WARN RootClass:215 - composite-id class does not override hashCode(): events.Event_Organizer
11:56:33,625  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
11:56:33,625  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
11:56:33,625  INFO DriverManagerConnectionProvider:45 - autocommit mode: true
11:56:33,734  INFO DriverManagerConnectionProvider:80 - using driver: sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MyOracle
11:56:33,734  INFO DriverManagerConnectionProvider:86 - connection properties: {user=system, password=****, autocommit=true}
11:56:39,671  INFO SettingsFactory:89 - RDBMS: Oracle, version: 10.02.0010
11:56:39,671  INFO SettingsFactory:90 - JDBC driver: JDBC-ODBC Bridge (SQORA32.DLL), version: 2.0001 (10.02.0001)
11:56:39,843  INFO Dialect:152 - Using dialect: org.hibernate.dialect.Oracle9Dialect
11:56:39,843  WARN Oracle9Dialect:37 - The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
11:56:39,859  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
11:56:39,875  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
11:56:39,875  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
11:56:39,875  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
11:56:39,875  INFO SettingsFactory:154 - JDBC batch size: 15
11:56:39,875  INFO SettingsFactory:157 - JDBC batch updates for versioned data: enabled
11:56:39,875  INFO SettingsFactory:162 - Scrollable result sets: enabled
11:56:39,875  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled
11:56:39,875  INFO SettingsFactory:178 - Connection release mode: auto
11:56:39,875  INFO SettingsFactory:202 - Maximum outer join fetch depth: 1
11:56:39,875  INFO SettingsFactory:205 - Default batch fetch size: 1
11:56:39,875  INFO SettingsFactory:209 - Generate SQL with comments: disabled
11:56:39,875  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
11:56:39,890  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
11:56:39,890  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
11:56:39,921  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
11:56:39,921  INFO SettingsFactory:225 - Query language substitutions: {yes='Y', no='N'}
11:56:39,921  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
11:56:39,921  INFO SettingsFactory:235 - Second-level cache: enabled
11:56:39,921  INFO SettingsFactory:239 - Query cache: disabled
11:56:39,921  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
11:56:39,921  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
11:56:39,921  INFO SettingsFactory:259 - Cache region prefix: hibernate.test
11:56:39,937  INFO SettingsFactory:263 - Structured second-level cache entries: disabled
11:56:39,984  INFO SettingsFactory:283 - Echoing all SQL to stdout
11:56:39,984  INFO SettingsFactory:290 - Statistics: disabled
11:56:39,984  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
11:56:39,984  INFO SettingsFactory:309 - Default entity-mode: pojo
11:56:39,984  INFO SettingsFactory:313 - Named query checking : enabled
11:56:40,656  INFO SessionFactoryImpl:161 - building session factory
11:56:41,265  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
11:56:41,437 DEBUG SQL:401 -
    select
        max(EVENT_ID)
    from
        EVENTS
Hibernate:
    select
        max(EVENT_ID)
    from
        EVENTS
Event saved with ID = 10
Event updated with ID = 10
End of Program
11:56:42,015 DEBUG SQL:401 -
    select
        event_orga_.EVENT_ID,
        event_orga_.FIRSTNAME as FIRSTNAME1_,
        event_orga_.LASTNAME as LASTNAME1_,
        event_orga_.PHONE as PHONE1_
    from
        EVENT_ORGANIZERS event_orga_
    where
        event_orga_.EVENT_ID=?
Hibernate:
    select
        event_orga_.EVENT_ID,
        event_orga_.FIRSTNAME as FIRSTNAME1_,
        event_orga_.LASTNAME as LASTNAME1_,
        event_orga_.PHONE as PHONE1_
    from
        EVENT_ORGANIZERS event_orga_
    where
        event_orga_.EVENT_ID=?
11:56:42,031  WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: S1000
11:56:42,031 ERROR JDBCExceptionReporter:78 - General error
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not retrieve snapshot: [events.Event_Organizer#component[eventId]{eventId=10}]
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.persister.entity.AbstractEntityPersister.getDatabaseSnapshot(AbstractEntityPersister.java:1052)
   at org.hibernate.engine.StatefulPersistenceContext.getDatabaseSnapshot(StatefulPersistenceContext.java:246)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:189)
   at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:512)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:80)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
   at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:218)
   at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
   at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
   at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
   at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
   at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at client.TestClient.main(TestClient.java:70)
Caused by: java.sql.SQLException: General error
   at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbc.SQLExecute(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.execute(Unknown Source)
   at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(Unknown Source)
   at org.hibernate.persister.entity.AbstractEntityPersister.getDatabaseSnapshot(AbstractEntityPersister.java:1025)
   ... 22 more


With these exception details,i couldn't understand what's wrong.
Can any one help me,to solve this problem.

Thank q very much,
siri.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 4:09 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Toss out the JDBC-ODBC piece of crap and use the Oracle JDBC driver. You should get back a real Oracle error message (plus an ORA-nnnn code) which you can go on. Your connect string should look something like jdbc:oracle:thin:@<hostname>:1521.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 6:02 pm 
Newbie

Joined: Thu May 01, 2008 4:53 pm
Posts: 11
Thanks for the reply,
I changed below tag
Code:

<property name="connection.driver_class">
      sun.jdbc.odbc.JdbcOdbcDriver
</property>

As
Code:
<property name="connection.driver_class">
       oracle.jdbc.driver.OracleDriver
</property>

Then what i have to write for below tag
Code:
<property name="connection.url">
       jdbc:odbc:MyOracle
</property>

Here MyOracle is my user data source name.
Can u please tell me this.
Thank q very much,
siri.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 9:08 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Re-read my prior post, I listed an example Oracle connect URL :)

Also, once you get out of development, do not under any circumstances use the hibernate connection pooling (connection.* properties). You should set up a proper DataSource using your appserver, container or Spring. The Hibernate manual will help you with this.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 11:04 pm 
Newbie

Joined: Thu May 01, 2008 4:53 pm
Posts: 11
Thanks,
I changed those two tags.Now i got a new exception like below,
Code:
22:57:22,031  INFO Environment:514 - Hibernate 3.2.6
22:57:22,031  INFO Environment:532 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=system, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@localhost:1522:XE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
22:57:22,046  INFO Environment:563 - using java.io streams to persist binary types
22:57:22,046  INFO Environment:681 - Bytecode provider name : cglib
22:57:22,046  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
22:57:22,109  INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml
22:57:22,109  INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml
22:57:22,406  INFO Configuration:559 - Reading mappings from resource : events/event.hbm.xml
22:57:22,781  INFO HbmBinder:300 - Mapping class: events.Event -> EVENTS
22:57:22,812  INFO Configuration:559 - Reading mappings from resource : events/event_Organizer.hbm.xml
22:57:22,890  INFO HbmBinder:300 - Mapping class: events.Event_Organizer -> EVENT_ORGANIZERS
22:57:22,921  INFO Configuration:1547 - Configured SessionFactory: null
22:57:22,937  INFO HbmBinder:2382 - Mapping collection: events.Event.eventOrganizers -> EVENT_ORGANIZERS
22:57:23,265  WARN RootClass:210 - composite-id class does not override equals(): events.Event_Organizer
22:57:23,265  WARN RootClass:215 - composite-id class does not override hashCode(): events.Event_Organizer
22:57:23,281  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
22:57:23,281  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
22:57:23,281  INFO DriverManagerConnectionProvider:45 - autocommit mode: true
22:57:23,296 FATAL DriverManagerConnectionProvider:65 - JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
   at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
   at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
   at client.TestClient.openSession(TestClient.java:26)
   at client.TestClient.main(TestClient.java:64)
Exception in thread "main" org.hibernate.HibernateException: JDBC Driver class not found: oracle.jdbc.driver.OracleDriver
   at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
   at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
   at client.TestClient.openSession(TestClient.java:26)
   at client.TestClient.main(TestClient.java:64)
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
   at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
   ... 8 more


Can u please tell me what is the problem now?

Thanks,
siri.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 11:12 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 4:57 am
Posts: 22
Location: Bangalore,India
The Orcale Driver Class is not in the classpath.

Add the classes11.jar or classes12.jar or ojdbc14.jar which ever is available during the Orcale installation in the classpath.

_________________
Naresh Waswani
+91-9986461501


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.