-->
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.  [ 1 post ] 
Author Message
 Post subject: Null Object Pattern
PostPosted: Sun Nov 01, 2009 4:23 pm 
Newbie

Joined: Mon Dec 15, 2008 11:53 am
Posts: 6
Hi there. I have a question about subject. Consider the following hypothetical example.
Code:
@Entity
public class Order {
  private Customer customer;
 
  public void setCustomer(Customer customer) {
    this.customer = customer;
  }

  public Customer getCustomer() {
        if (customer == null)
          return Customer.createNullCustomer();
        else
          return this.customer;

  }

 
}

@Entity
public class Customer {
  static Customer createNullCustomer() {
    return new NullCustomer();
  }

  public boolean isNull() {
    return false;
  }
}

public class NullCustomer extends Customer {
  public boolean isNull() {
    return true;
  }
}

@Entity
public class Item{
    private Customer customer;
    private Order order;

    public void doSomething() {
      this.customer = order.getCustomer();
    }
}


Suppose, we have NullCustomer in Item. I want to persist Item instance in such way, that there will be null in database for customer if it's NullCustomer. How can I do that without creating custom user type?


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

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.