-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: @NotNull or @NotEmpty not working
PostPosted: Mon Jun 23, 2008 8:27 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
I got a strange behaviour by using hibernate validators:

I take that:

In my entity-Bean, I use the hibernate-validator-tags:

Code:
@Length(min=4)
@NotNull(message="No Password")
@Column(name = "PASSWORD", nullable = false)
public String getPassword() { return password; }


I integrated the validator in an xhtml-page by using the Seam-Tag <s:validate/>. I got the following exception:

Code:
...
Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1401)
   at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
   at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
   at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
   at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
   at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:605)
   ... 46 more
Caused by: javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: Entity.Persons
   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:527)
   at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
   at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
   ... 51 more
Caused by: org.hibernate.validator.InvalidStateException: validation failed for: Entity.Persons
   at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
   at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:167)
   at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:156)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:49)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
   ... 56 more
...


The strange thing is, when I use the Tag "@Length" instead of "@NotNull" or "@NotEmpty", than my page with the hibernate validations works well.

Code:
@Length(min=1)
@Column(name = "PASSWORD", nullable = false)
public String getPassword() { return password; }


Why is that so? I wanna use @NotNull or @NotEmpty. to validate, that the field 'password' does not be empty. What is wrong?

nimo


Top
 Profile  
 
 Post subject: solved
PostPosted: Mon Jun 23, 2008 8:43 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
okay, now I am using the "required="true"-Attribute. Then the validation works. But also without the @NotNull.

So how can I use the @NotNull instead of "required="true" ??

This validation works (validate the length):

Code:
 
@Length(min=4, max=60)
@Column(name = "PASSWORD")
public String getPassword() { return password;}


but this validation works NOT:

Code:
@NotNull
@Column(name = "PASSWORD")
public String getPassword() { return password;}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 10:17 pm 
Newbie

Joined: Thu Jul 17, 2008 10:10 pm
Posts: 1
I have also encountered the same problem. For some reason, the field is populated with empty String(""). JSF defect? or Seam defect?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 17, 2008 11:41 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
johnnyren wrote:
JSF defect? or Seam defect?


are you sure. it is a JSF or Seam defect. dude double check that your validation phase is done successfully.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.