Hi all,
Would JBoss validate an Entity's attribute for length?
@Entity
| 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:
anonymous wrote :
| 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:
anonymous wrote :
| java.lang.reflect.UndeclaredThrowableException
| 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?
Thanks
-tony
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4027664#4027664
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4027664
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user