Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javax.ejb.EJBException when trying to inject data into database on form input

 
Benji Xu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again!

I'm trying to inject data into database based on form input but i'm facing a nasty exception and I can't seem to be able to wrap my head around a scalable solution and I have tried many... Maybe you can help? How can I find the needle in this haystack?
It's very hard to pinpoint with so many attributes! I tried to remove @NotNull from every class but the exception remains no matter what I try... I also changed persistence.xml to value="None" to turn it off but it was a bad idea as expected and it didn't help.

at controller.ControllerServlet.doPost(ControllerServlet.java:409) refers to code:
at session.OrderManager.addCustomer(OrderManager.java:55) refers to code:
at session.OrderManager.placeOrder(OrderManager.java:34) refers to code:





 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrap the code in OrderManager.addCustomer in a try-catch block, catch any ConstraintViolationException, log it and its violation, and rethrow:
If that still doesn't give you enough information, log each separate constraint violation, especially the message and property path.
 
Benji Xu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my case the error meant:

I had a constraint violated on my model that was detected before persisting to the datastore. This meant that my Customer or related entities had a Validation (eg. @NotNull, @Size) that was not honored.

The solution:

Removing every @NotNull annotation in my database and making sure the length of the form input did respect the database columns @Size or increasing it. Hope it can help you as well if you are seeing this!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!