Monday, January 11, 2016

HibenateTools and Oracle

1. If see this error as follows,

org.hibernate.cfg.jdbcbinder Exception and it says Duplicate class name 'Syscatalog' generated for 'org.hibernate.mapping.Table(SYS.SYSCATALOG_)'. Same name where generated for org.hibernate.mapping.Table(SYS.SYSCATALOG_)

just add property 'hibernate.default_schema' in hibernate.cfg.xml, for example,
 <property name="hibernate.default_schema">ABC</property>

2. configure @Id for oracle sequence

CREATE TABLE MY_TABLE(
    ID NUMBER NOT NULL,
    CONSTRAINT MY_TABLE_PK PRIMARY KEY(ID)
); 

CREATE SEQUENCE mytable_seq START WITH 1 INCREMENT BY 1 CACHE 10 NOCYCLE;

  @SequenceGenerator(name = "SEQGEN_MYTABLE", sequenceName = "mytable_seq",
      allocationSize = 1, initialValue = 1)
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQGEN_MYTABLE")
  @Column(name = "ID")
  public long getId() {
    return this.id;

  }