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

  • Home
  • SEARCH
  • 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 6775303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:53:28+00:00 2026-05-26T15:53:28+00:00

So this might be kind of a dumb question but when do you register

  • 0

So this might be kind of a dumb question but when do you register classes with:

ObjectifyService.register( User.class );

Currently, I’m doing this in the constructor of an interface-like class that I use in my other classes to simplify usage of the Data store specifically to my application. However, I’m getting this error:

Attempted to register kind ‘User’ twice

So, I guess my question is how often and specifically when do you register classes in Objectify?

Thanks!

P.S. Here’s my entire class:

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.persistence.Id;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.annotation.Indexed;
import com.googlecode.objectify.annotation.Unindexed;

public class UsersService {

    Objectify ojy;

    public UsersService(){
        ObjectifyService.register( User.class );
        ojy = ObjectifyService.begin();
    }

    public void regUser(String email, String password, String firstName, String lastName){
        //TODO: Check syntax if email
        //TODO: store encrypted password
    }

    public void regUser(String email, String password, String firstName){
        regUser(email, password, firstName, null);
    }

    public void regUser(String email, String password){
        regUser(email, password, "", "");
    }

    public boolean checkFor(Long acc_id){
        User checked_user = ojy.find(User.class, acc_id);
        if(checked_user == null){
            return false;
        }else{
            return true;
        }
    }

    public User getUser(String email, String password) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException{
        String pass_enc = MyUtils.getEncrypted(password);
        Iterable<User> users = ojy.query(User.class).filter("email", email).filter("password", pass_enc);
        Iterator<User> iter = users.iterator();
        if(iter.hasNext()){
            return iter.next();
        }else{
            return 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-26T15:53:28+00:00Added an answer on May 26, 2026 at 3:53 pm

    Update

    Here is the Best Practice Solution:

    Use Your Own Service ,
    This guarantees that your entities are registered before you use Objectify, but doesn’t necessarily impact application startup for requests which do not access the datastore.

    import com.googlecode.objectify.Objectify;
    import com.googlecode.objectify.ObjectifyFactory;
    import com.googlecode.objectify.ObjectifyService;
    
    
    public class OfyService {
        static {
            ObjectifyService.register(User.class);
        }
    
        public static Objectify ofy() {
            return ObjectifyService.begin();//prior to v.4.0 use .begin() , 
                                            //since v.4.0  use ObjectifyService.ofy();
        }
    
        public static ObjectifyFactory factory() {
            return ObjectifyService.factory();
        }
    
    }
    

    Then use it like this:

    public User createUser(User pUser) {
    
        Objectify objectify = OfyService.ofy();
        objectify.put(pUser);
    
        return pUser;
    }
    

    Original Answer (better use the code above):

    you should do it this way in your class, just put a static block like this:

    static{
        ObjectifyService.register( User.class );
    }
    

    p.s , you take a look at the best practice of objectify too

    http://code.google.com/p/objectify-appengine/wiki/BestPractices

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

Sidebar

Related Questions

This question might be kind of elementary, but here goes: I have a SQL
This might be a dumb question but are ( ) supported by sed? I
This might be (read: probably is) a dumb question, but here goes... Is there
Okay, so this might be kind of strange but here's the question: I have
This might be kind of a silly question, but in C++, when I want
I am kind of new to C# and Asp.Net, so this question might sound
I know this question has kind-a started religious wars in past and there might
This might seem like a very easy question for some of you folks, but
This might be a simple question but I've searched and searched and can't find
This might be a very basic question but it confuses me. Can two different

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.