0

I cannot figure out why I am not seeing an exception for trying to insert 20 characters into a 10byte oracle table field... I confirmed the bad (too large string) is in the object, and the database does show varchar2(10).

Here is the code (extra logic removed for simplicity)

boolean isSuccess = false;
arrMyObject
for(int i = 0; i < arrMyObject.length; i++) {
    try {
        MyObject myObject = arrMyObject[i];
        em.persist(myObject);
        return true;
    } catch (Exception e) {
        System.out.println("Error");
        throw (e);
    }
}
return false;

I am not receiving an Exception (expecting some ORA exception). Nothing is being printed out, and I am receiving a TRUE value in my calling method. Also, nothing gets inserted to the table, which IS expected. With valid data I confirmed insert works.

Whats going on?

Mohit Gupta
  • 33
  • 1
  • 5
Kairan
  • 5,342
  • 27
  • 65
  • 104
  • and what transaction are you using? – Neil Stockton Aug 08 '15 at 17:31
  • @NeilStockton I am new to Hibernate, I am not sure if this is the answer you are asking for: – Kairan Aug 08 '15 at 17:44
  • no. With an EntityManager you can either perform operations with a LocalTransaction (and have em.getTransaction().begin()/commit()) or use a JTA transaction. You need to know what you're using – Neil Stockton Aug 08 '15 at 17:47
  • well, well ... JBossTransactionManagerLookup => 'A TransactionManagerLookup lookup strategy for JBoss AS.' => JTA container managed transaction. – Gab Aug 08 '15 at 18:25
  • @NeilStockton, moreover you 're confounding 2 things, local / Jta and container / user managed transaction – Gab Aug 08 '15 at 18:30
  • @Gab Having some persistence property doesn't mean he is actually using JTA ... it means if JTA is enabled for the persistence context then use that lookup class. The persistence.xml is basic viewing here, so unless its posted then not much can be said other than look at the log and see whether your transaction is actually being committed. – Neil Stockton Aug 08 '15 at 18:32
  • my dear, if the transactionManager is resolved using jndi lookup a JTA transaction manager will be retrieved and nothing else. The way he uses it ie. user (bean) managed or container managed is still up to him, I agree, my statement was over confident. But I persist you're confounding 2 things. – Gab Aug 08 '15 at 18:44

1 Answers1

2

IMHO, at the point you test, the current transaction is not yet committed and the hibernate session is so not flushed yet, so you didn't reach the database and did not receive the error. Try to flush the hibernate session just to see (don't let the flush call in production)

Gab
  • 7,869
  • 4
  • 37
  • 68