0 Replies Latest reply on Mar 13, 2007 3:47 PM by Tony Mai

    Does JBoss validate EntityBean length setting?

    Tony Mai Apprentice

      Hi all,

      Would JBoss validate an Entity's attribute for length?

      public class ExampleName implements Serializable {
       private String name;
       @Column(nullable = false, length=25)
       public String getName() {

      when I invoke the following code
      ExampleName ex = new ExampleName();
      ex.setName("A long line that violates the max length set for ExampleName");

      The server threw the following exception:

      12:35:37,312 WARN [JDBCExceptionReporter] SQL Error: 8152, SQLState: 22001
      12:35:37,312 ERROR [JDBCExceptionReporter] String or binary data would be truncated.
      12:35:37,312 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.DataException: could not insert: [com.judots.ExampleName]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
      Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.
      at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)

      while on the client junit test, I would receive the following error:

      at $Proxy5.createExchange(Unknown Source)
      at com.judots.test.Tests.createExampleName(Tests.java:29)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
      Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerException
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

      It would be nice to have JBoss validate the length automatically without us having to declare Hibernate's validation explicitly. After all, we are using Hibernate within JBoss are we not?