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: Oracle issue
PostPosted: Thu Oct 01, 2009 1:38 am 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
G'day to All,
I have this interesting issue with Oracle 11g DB.
I have all set up and working with MySQL and now I'm trying to switch to Oracle.
I've created the table to match what I have on MySQL, then I've modified the config file
so that the URL, username, password and dialect are now all for Oracle. When I run my app however nothing gets written to the DB.
I tried all kinds of changes to the config file but nothing works. No new row is ever created and additionally Hibernate reports no errors
and no exceptions is thrown.
I know Hibernate sees the database because when I changed one of the column's name, Hibernate created one with new name.
The drivers got recognized, username.tablename is all correct. I've added one record manually and Hibernate sees it.
It's reporting one record there. I'm giving up.....
I modified my table such that there are only two columns, one for primary key called keyId which gets automatically incremented and one for simple Long value: number(20,0) still no errors/exceptions and no new rows got created. What seems to be a problem?
As soon as I change the config file to point to MySQL all works just fine without any changes done to the code, just the config file. New rows got created and populated with data.
I ran my app in the debug mode and I see values passed in, like the auto incremented value that comes from the DB. So partially Hibernate works I'd say....
I'm new to the Hibernate and Oracle so If you know or have ran into a similar problem please share the solution if you've got one.
I suspect that the Oracle DB doesn't like something about my config file or simply needs additional parameters....
I've also tried ojdbc drivers versions ojdbc14.jar, ojdbc5.jar, ojdbc6.jar but this didn't help; still nothing.
Thanks for any suggestion?


Top
 Profile  
 
 Post subject: Re: Oracle issue
PostPosted: Thu Oct 01, 2009 2:42 am 
Newbie

Joined: Thu Oct 01, 2009 2:20 am
Posts: 2
could you share your hibernate config file ? If you are able to see the data in oracle database using the application that means your connection is ok, might b some configuration problem , check your hbm2ddl should be None or update.

Thanks,
Pankaj Pushp


Top
 Profile  
 
 Post subject: Re: Oracle issue
PostPosted: Thu Oct 01, 2009 12:14 pm 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
Here is the config file. It has both properties for Oracle and MySQL - which are commented out....
I did change the hbm2ddl from Update to None but it didn't help.
Any other suggestion?


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<!--<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>-->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!--<property name="hibernate.connection.url">jdbc:mysql://localhost/HibernateTest</property>-->
<property name="hibernate.connection.url">jdbc:oracle:thin:@//someserver:1521/DB</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="show_sql">true</property>
<!-- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>-->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.hbm2ddl.auto">Update</property>

<!-- Mapping files -->
<mapping resource="record.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: Re: Oracle issue
PostPosted: Thu Oct 01, 2009 2:20 pm 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
I got it!
It turned out this had nothing to do with my config file.
I just hope this will help others, as I spent so much time on this issue....
So apparently Oracle needs explicit transaction commit() method call.
I used to have this:
Code:
session.save(some_record);
session.flas();


This will work fine with MySQL (I didn't test it with other databases out there)
However with Oracle we need:

Code:
Transaction t = session.beginTransaction();
session.save(r);     //this actually writes to a DB
session.flush();
t.commit();


I guess MySQl has auto-commit feature and Oracle doesn't or the one I'm using doesn't have this feature turned on.
(I don't know that much about Oracle DB)
In any case, this was the issue......
G'day to all


Top
 Profile  
 
 Post subject: Re: Oracle issue
PostPosted: Fri Oct 02, 2009 2:37 pm 
Newbie

Joined: Thu Oct 01, 2009 2:20 am
Posts: 2
Greggg wrote:
I got it!
It turned out this had nothing to do with my config file.
I just hope this will help others, as I spent so much time on this issue....
So apparently Oracle needs explicit transaction commit() method call.
I used to have this:
Code:
session.save(some_record);
session.flas();


This will work fine with MySQL (I didn't test it with other databases out there)
However with Oracle we need:

Code:
Transaction t = session.beginTransaction();
session.save(r);     //this actually writes to a DB
session.flush();
t.commit();


I guess MySQl has auto-commit feature and Oracle doesn't or the one I'm using doesn't have this feature turned on.
(I don't know that much about Oracle DB)
In any case, this was the issue......
G'day to all


Yes, your config file looks fine, you are correct u have to commit and flush, i have used HibernateDaoSupport that commit and flush automatically.
Thanks


Top
 Profile  
 
 Post subject: Re: Oracle issue
PostPosted: Thu Oct 08, 2009 2:39 am 
Newbie

Joined: Wed Sep 30, 2009 8:28 am
Posts: 10
If i want map 2 or more files in hibernate.cfg.xml?
Is this the only way to map...
<mapping resource="table1.hbm.xml"/>
<mapping resource="table2.hbm.xml"/>

Can i have a separate file which contains the mapping elements and include that file into my hibernate.cfg.xml?
So that i can add/delete table mapping in that separate file and not in original hibernate.cfg.xml.

Is there any such way?


Thanks in advance


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.