• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto Increment id in MySQL to a sequence id in Oracle Issue

 
Gabriela Rios
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I originally started testing hibernate using MySQL. I got it to work but now that I moved it to Oracle. I can't get the insertion to the database to generate the id. It keeps adding/updating an user with id = 0.

This is the error that I'm getting: Caused by: java.sql.SQLException: Invalid column type: getInt not implemented for class oracle.jdbc.driver.T4CRowidAccessor

This was my getId() - This worked in MySQL.


This is the trigger I have in Oracle

CREATE OR REPLACE TRIGGER "CHS"."USERS_TRG" BEFORE INSERT ON USERS
FOR EACH ROW
BEGIN
<<COLUMN_SEQUENCES>>
BEGIN
IF :NEW.USERID IS NULL THEN
SELECT USERS_SEQ.NEXTVAL INTO :NEW.USERID FROM DUAL;
END IF;
END COLUMN_SEQUENCES;
END;

What should I change to now make it work in Oracle?

Thanks for your help
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This forum is for Spring Framework questions. Not ORM questions. There is a separate forum for that.

Please post to the appropriate forum.

Moving this.

Thanks

Mark
 
Bogdan Baraila
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In oracle you will need to use a sequence (create sequence hibernate_sequence
start with 1
increment by 1
nomaxvalue; ) and instead of IDENTITY you can use Sequence or Native.
 
Gabriela Rios
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this working by doing the follwing:



and also I had the wrong dialect in my hibernateProperties: <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic