Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

avoid inserting empty string

 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Seam,Hibernate and Mysql. In the case of not null string(ie. Empty("")) , it is being inserted in database. , I know Oracle replaces "" with null, but mysql doesn't function that way. So what to do to avoid this?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to fix your application logic to correct this behaviour. If you do not want empty strings to be persisted don't set properties in your objects to be empty strings.
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jignesh Patel, How do you configure the Hibernate Entity?..

Yes, you could try to what Paul Sturrock suggested..
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:You'll need to fix your application logic to correct this behaviour. If you do not want empty strings to be persisted don't set properties in your objects to be empty strings.

In my hibernate entity I have tried to set @NotEmpty, but was giving me problem. Is there any other way where I need to let hibernate entity know about this?
At the application level, I have fixed by setting null. But wondering, can I do diretctly at the hibernate entity level.
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@NotEmpty is annotations in Hibernate Validator...
//before the entity persisted, we could check if there's any empty field..

 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leonardo Carreira wrote:@NotEmpty is annotations in Hibernate Validator...
//before the entity persisted, we could check if there's any empty field..



Are you telling to check in setField() method...

I did that but I do have other scenario in those case I am getting error message.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In my hibernate entity I have tried to set @NotEmpty, but was giving me problem.

What problem? Can you give use some details (otherwise we can't help)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic