-->
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: Hibernate 4.2.21 ORA-00001: unique constraint
PostPosted: Tue May 24, 2016 9:07 pm 
Newbie

Joined: Tue May 24, 2016 9:03 pm
Posts: 3
I'm working with Hibernate 4.2.21.Final and Oracle Database 12c 12.1.0.2.0 - 64bit Production, we have defined in our Jboss a JNDI for our DataSource, We have a strange problem in one of our Tables - only in this case, this problem it's not usual may be we have in total 2 cases during this two weeks:

When we want to save a Object in the DB, and we got this error:

Code:
2016-05-24 08:16:30,425 INFO
[org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (rommApp)
HHH000010: On release of batch it still contained JDBC statements

2016-05-24 08:16:30,427 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (rommApp) SQL
Error: 1, SQLState: 23000 2016-05-24 08:16:30,427 ERROR
[org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (rommApp)
ORA-00001: unique constraint (rommDBA.SYS_C006240) violated



This constraint it's a Primary Key, the problem seems to be we are using a primary key that it's in use, but if this fail should be fail more times, when I try to save the Object the second time works.

There is a good explanation about this random error?

Sequence:

Code:
--
-- ORDER_SEQ  (Sequence)
--
CREATE SEQUENCE rommDBA.ORDER_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  NOCACHE
  ORDER
  NOKEEP
  GLOBAL;

Table:

Code:
--
-- ORDERS  (Table)
--
CREATE TABLE ROMMDBA.ORDERS
(
  ORDER_ID                 NUMBER(19)           NOT NULL,
  ORDER_NAME                VARCHAR2(255 CHAR),
  ORDER_CREATEDBY          VARCHAR2(255 CHAR)   NOT NULL,
  ORDER_CREATEDON          TIMESTAMP(6)         NOT NULL,
)
TABLESPACE ROMM
RESULT_CACHE (MODE DEFAULT)
PCTUSED    40
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          1M
            NEXT             1M
            MAXSIZE          UNLIMITED
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
            FLASH_CACHE      DEFAULT
            CELL_FLASH_CACHE DEFAULT
           )
LOGGING
COMPRESS FOR OLTP
NOCACHE
NOPARALLEL
MONITORING;

Model Class:

Code:
@Id
    @SequenceGenerator(name = "OrderSequence", sequenceName = "order_seq", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="OrderSequence")   
    @Column(name = "order_id", unique = true, nullable = false)
    private Long id;

DAOImpl:

Code:
public Order  addOrder(Order order) {
            Session session = SessionFactory.getSessionFactory().openSession();
            try {
                session.beginTransaction();
                session.save(order);
                session.getTransaction().commit();
            } catch (HibernateException e) {
                session.getTransaction().rollback();
                throw new HibernateException(e);
            } finally {
                session.close();
            }

            return order;
        }


Top
 Profile  
 
 Post subject: Re: Hibernate 4.2.21 ORA-00001: unique constraint
PostPosted: Wed May 25, 2016 12:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The mapping is fine. Check your driver as well, maybe there is some issue there that might have got fix in a newer version.

Are you sure SYS_C006240 is for primary key because that cannot be tell from your post.


Top
 Profile  
 
 Post subject: Re: Hibernate 4.2.21 ORA-00001: unique constraint
PostPosted: Wed May 25, 2016 3:21 am 
Newbie

Joined: Tue May 24, 2016 9:03 pm
Posts: 3
Hi mihalcea_vlad,

Yes I checked that the constraint it's Primary Key.

I was looking for more info in stackoverflow, I found this two possibilities:

1- In our config the hibernate.id.new_generator_mappings is false by default in Jboss 6.4 EAP, in the doc the recommend to use true, but I can't see any conection with this problem.

2.-We didn't define in our Sequence the Increment BY according with our allocationSize=1, here there ir more info about that:

http://stackoverflow.com/questions/9861 ... 2#10653792

So you MUST declare the same value on both allocationSize (Hibernate) AND sequence increment (DB)
Otherwise, you'll notice negative values or constraint errors raised from your DB because of primary key collisions.



Code:
<!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>

      <property name="hibernate.jdbc.batch_size">30</property>
      <property name="hibernate.default_schema">rommApp</property>
      <mapping class="backend.model.romm.Order" />

   </session-factory>
</hibernate-configuration>
[/code]

Code:
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
configuration.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
configuration.setProperty("hibernate.connection.datasource", "jdbc/rommApp");


In the JNDI the Connection String is:

Code:
jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=OFF)(FAILOVER=ON)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=XXXXXX)(Port=XXXX))(ADDRESS=(PROTOCOL=TCP)(Host=XXXXXX)(Port=XXXX)))(CONNECT_DATA=(SERVICE_NAME=XXXXX)))


Can be any of this cases the origin of this error?


Top
 Profile  
 
 Post subject: Re: Hibernate 4.2.21 ORA-00001: unique constraint
PostPosted: Wed May 25, 2016 4:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can try this mapping that was tested on Hibernate 4.3:

Code:
@Id
@GenericGenerator(
    name = "sequence",
    strategy = "sequence",
    parameters = {
        @org.hibernate.annotations.Parameter(
            name = "sequence",
            value = "order_seq"
        )
     
})
@GeneratedValue(generator = "sequence")
@Column(name = "order_id")
private Long id;


Top
 Profile  
 
 Post subject: Re: Hibernate 4.2.21 ORA-00001: unique constraint
PostPosted: Wed May 25, 2016 5:43 am 
Newbie

Joined: Tue May 24, 2016 9:03 pm
Posts: 3
what is the difference with the method I use?, and there is any known BUG about this in 4.2.21?


Top
 Profile  
 
 Post subject: Re: Hibernate 4.2.21 ORA-00001: unique constraint
PostPosted: Wed May 25, 2016 6:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It might not use the SequenceStyleGenerator. Try it and see if it works. As for bugs in that version, I'm not aware of any such issue. But, to be really sure, you can also check JIRA.


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.