• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate and oracle sequence id

 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my oracle database, I first created "MyTable" Table and then created "MyTable_SEQ" SEQUENCE (I put the syntax in one script starting with table creation followed by SEQ creation). Then I do

insert into MyTable(ID, NAME) VALUES(MyTable_SEQ.NEXTVAL, 'John');

I saw the row in database by doing select in sqlplus.

However, when I use hibernate to retrieve the data, I got nothing. It was not any exception or error, just got an empty result. However, interestingly, if I use hibernate code to insert another row in this table, I could retrieve that row inserted by hibernate code. i.e. anything that's inserted from SQLPLUS GUI via explicitly runing the above "insert" statement, can't be retrieved by hibernate. Anything inserted by hibernate code can be retrieved by hibernate code.

In my hibernate conf I have setting like

<class name="MyTable" table="MyTable">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">MyTable_SEQ</param>
</generator>
</id>
<property name="name" column="NAME"/>
</class>

Does anyone have any idea ? I guess there is something wrong with the database part. But I can insert and retrieve data from splplus.

Thank you.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you commit the record that you inserted in SQLPlus? Remember that things run in transactions that until commited are only visible by the client that is in the transaction.

Mark
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HaHa, Mark you are the man ! I think that's the problem. Thank you !
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark, one more stupid question --- when I ran the "create or replace table.." and "create sequence.." script, the script doesn't include any "commit" either. But why were the tables and sequence created without problem ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic