Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

avoid inserting empty string

 
Ranch Hand
Posts: 676
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 676
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 676
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)?
 
reply
    Bookmark Topic Watch Topic
  • New Topic