Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:38:45+00:00 2026-06-18T10:38:45+00:00

I am facing a design decision in my GWT + Hibernate project. I will

  • 0

I am facing a design decision in my GWT + Hibernate project.

I will explain my question using a Company entity.

@Entity
@Table(name = "Company")
public class Company extends LightEntity implements BaseSerializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "Id")
    private int id;

    @Column(name = "Code")
    private String code;
    @Column(name = "Name")
    private String name;

    @Column(name = "Address")
    private String address;

    @Column(name = "ContactNumber1")
    private String contactNumber1;

    @Column(name = "ContactNumber2")
    private String contactNumber2;

    @Column(name = "EMail")
    private String email;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "company", cascade = CascadeType.ALL)
    private List<CompanyRegistration> companyRegistrations = new ArrayList<CompanyRegistration>();

    public Company() {
    }
    public Company(String code, String name) {
        this.setCode(code);
        this.setName(name);
    }

    // getters & setters
}

A valid Company object must always have a valid code and name. Rest of the properties are optional. Hence, I have provided a two-args constructor to ensure the creation of a valid object.

Now.

I am used to validate data in setters. I also use these setters in my constructor(s). These ensure that a new object always has a valid state. This is/was my plan in implementing the Hibernate entities.

However, GWT-RPC mandates default noargs constructor so that it can be used for deferred binding. But that will also allow anyone to create an empty object, which is not desirable in most of my Hibernate entities. For example, a Company must always be constructed with a Code and a Name. A noargs constructor defies that rule.

Now, Hibernate has implemented a standard (JSR-303, if my memory doesn’t betray me) for validation framework. It lets you invoke validations on an already created object.

My problem has arisen due to the noargs constructor. If it had not been mandatory, I would have done away with validations in setter.

If I implement validations in setters, that means that an invalid object will fail as fast as possible. I won’t need to invoke a validation on an object on client side. But, an empty object (created using the noargs constructor) can’t be validated that way. It might make it way to the service, implying that I also have to implement validations, a lot of which might be the same as the setters, in the service layer.

If I implement the validation framework, then I have to invoke validation on each object I create on the client side. If I forget to validate one, it can go to service layer in an invalid state. However, I can easily use the same framework on the service layer.

One solution that I have thought of is to implement validations in setters anyway, but also use a Validator in the service layer, before sending an object to persist in database. That way, the client side will be restricted by the setters automatically. On the other hand, if an empty object is sent anyhow to the server side, it will be caught by the Validator on service layer. An exception will be thrown to the user in both the cases.

I think this is not the best solution, however. So, I would like to get one.

EDIT – I am anyways using annotations to put constraints on entity fields, so that Hibernate can use them for validation before persisting an object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:38:46+00:00Added an answer on June 18, 2026 at 10:38 am

    If your problem only stems from the mandatory zero-arg constructor for GWT-RPC, note you can make this constructor inaccessible to developers (even private if you want); GWT-RPC will access it using reflection whichever its visibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built recently a table using c# and asp.net and I was facing design
i am doing a database design using EAV. I am facing an issue when
I am facing some questions when trying to design an S3 application using ASP.NET
i'm facing a design problem within my project. PROBLEM i need to query solr
The project I am working on is facing a design dilemma on how to
I'm facing a design decision while developing an iPhone app library for which I'd
I'm facing the following design issue: There will be several prepared SQL statements where
I have the following database design: Employee Table: Username, Name, JobTitle, BadgeNo, IsActive, DivisionCode
I am facing a problem of design time support best practices. I am using
I want to design a Forum using Php but the problem I am facing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.