0

I'm working on extending a REST API written in Java using the Spring framework, Hibernate ORM and Jackson for JSON (de)serialization.

On a few API calls, I need to return a user's account given a provided value (say, a subscription ID). There are different types of accounts, so a type value is included so the client can determine what kind of account they're dealing with.

In my controller, I pass the provided user ID down to the service call which calls this method:

public Account getAccountBySubscriptionId(long subscriptionId) {
    ServiceSubscription subscription = subscriptionDAO.load(subscriptionId);
    if(subscription != null) {
        return subscription.getAccount();
    } else {
        return null;
    }
}

I would expect this to return JSON similar to this:

{
    "type":"account_type_goes_here",
    "id":1,
    "accountNumber":"100"
}

However, it appears that Hibernate's lazy loading is modifying the type value, as such (note that UserAccount is the class of the object):

{
     "type":"UserAccount_$$_javassist_1",
     "id":2,
     "accountNumber":"37"
}

How could I make Hibernate retain the original value for type instead of modifying it?

1 Answer 1

2

Are you sure there isn't an error in your logic that's returning the type of the object and not the string value of the type of the account?

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think so - similar code is used elsewhere which returns the account type as expected. I'll double check that though.
You were right - there was some weird logic in the model causing this. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.