Announcement Announcement Module
No announcement yet.
Spring,hibernate, oracle 9i Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring,hibernate, oracle 9i

    I have a table for student that has shippingAddressId, billingaddressId, creditCardId.

    I use studentForm bean by using struts and save student object by using hibernate into Oracle 9i.
    But I have this kind of error message. When i get this message, I rerun tomcat then it works. But sometimes I have same error..
    I dont know what is happening..

    student Id is generated by sequence in oracle. On the mappingfile, I use Integer type. Actually, studentId is mapping as NUMBER in oracle.
    what should i do?

    Data Access Failure
    (HibernateTemplate): data integrity violated by SQL ''; nested exception is java.sql.BatchUpdateException: ORA-01401: inserted value too large for column

  • #2
    You need to work out which column is getting the invalid value. You can most easily test that by a test outside the web container where it's quick to simulate such input. See the Testing (integration testing) chapter in the Spring Reference manual.

    It's probably a number that has too many digits or a String that is too long. Check the reference on the Oracle types you're using in your DDL.

    Or you could use a tool like Toad to investigate what happens when you manually run the SQL that Hibernate is generating (ask it to show SQL), with the same values.


    • #3

      Just a heads up, but you'll get the spew of the prepared statements that Hibernate is generating when it crunches up your mapping files - not straight SQL. You'll have to do a little editing before you dump it into Toad (or your SQL client o'choice)


      • #4
        If you use the odbc14_g.jar driver jar instead of odbc14.jar, you can put the following in your code around where the problem is occurring.,


        // code that gets Oracle error


        This generates a mile of output but will actually give you an error message that is useful.


        • #5
          You need to work out which column is getting the invalid value.
          The BatchUpdateException has normally a more meaningful SQLException attached. You can retrieve this exception by calling batchUpdateException.getNextException(). The original batch exception can be get by springException.getCause().

          I have altered the TestCase.runBare method for this. It really helps to quickly check whats going on.

          	public void runBare() throws Throwable {
          		try {
          		catch(Throwable throwable) {
          			throw getMeaningfulException(throwable);
          	private Throwable getMeaningfulException(Throwable throwable) {
          		return throwable instanceof NestedRuntimeException ?
          				getMeaningfulException((NestedRuntimeException)throwable) : 
          	private Throwable getMeaningfulException(NestedRuntimeException exception) {
          		Throwable nestedThrowable= exception.getCause();
          		if(nestedThrowable instanceof BatchUpdateException) 
          			throw new RuntimeException(
          					"BatchUpdateException: "+nestedThrowable.getMessage(),
          			throw exception;
          	private Throwable getMeaningfulException(BatchUpdateException e) {
          		Throwable nestedException=e.getNextException();
          		return nestedException instanceof BatchUpdateException ?
          						(BatchUpdateException)nestedException) : nestedException;
          Feel free to use this snippet. Maybe the org.springframework.test classes can also profitate from this. It helps with MySql and PostgreSql but I am not sure if this is useful in conjunction with the Oracle drivers. Just give it a try.


          Martin (Kersten)