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 7023883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:46:04+00:00 2026-05-27T23:46:04+00:00

We have a nullable (type long) column (named referral) in our MySQL database. We

  • 0

We have a nullable (type long) column (named referral) in our MySQL database. We use hibernate for ORM.

I am trying to get the value of the column for a given member. Some are null, and if its not, its an id that points to another member whose is the referrer.

The problem is in the java code I am trying to detect if that member’s column is null, if not, do something.

String referrerAffiliateId = Long.toString(member.getReferral());
if (referrerAffiliateId != null){
    //do something
}

member.getReferral() returns the value (type long) of the referral column. Some of those columns are null and some are not.

The above code compiles fine, but I get a nullPointerException when I call the method on a user whose referral column is null.

How do I properly do a detection on this?

Thanks in advance!

Full Answer:

Thanks to @Marcelo for the best correct answer.

Here is the code in its final state:

Long referrerAffiliateId = member.getReferral();
if (referrerAffiliateId != null) {
    //...
}
  • 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-05-27T23:46:04+00:00Added an answer on May 27, 2026 at 11:46 pm

    Assuming member.getReferral() returns a Long, use:

    if (member.getReferral() != null)
    

    In Hibernate, if you want to be able to detect nullability in a property, you must not use primitive types, because they will always have a default value 0 for longs.

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

Sidebar

Related Questions

We are trying to use Hibernate with a database that uses a lot of
Is there anyway to have the var be of a nullable type? This implicitly
Dynamic Data question: I have 2 fields of type Nullable<DateTime> on my model When
I have a nullable date in my database. I am connecting to it with
I have a nullable DateTime column in my SQL Server 2005 table called DateTimeDeleted.
I have a question on how to determine an object's Nullable property type. ObjectA
I have a nullable type, e.g. SomeEnum? and a set of values, e.g. IEnumerable<SomeEnum?>
I am trying to add data to a database, in grails but get this
I have an ASMX Web Service set up to use the HTTP GET method.
I've been trying to use polymorphic query with JPA (hibernate as provider) in the

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.