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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:33:31+00:00 2026-06-15T20:33:31+00:00

How can I inject the class UserProfile in this kind of statement? This is

  • 0

How can I inject the class UserProfile in this kind of statement? This is using Struts2 – Spring plugin.

( UserProfile userProfile = em.find(UserProfile.class,”1″);) —> I could don’t have any idea how to change this for injection style in spring?

package tester;

/**
 *
 * @author god-gavedmework
 */


import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import lotmovement.business.entity.UserProfile;



/**
 *
 * @author god-gavedmework
 */
public class Record_exist {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        EntityManagerFactory entityManagerFactory = 
        Persistence.createEntityManagerFactory("LotMovementPU");

        EntityManager em = entityManagerFactory.createEntityManager();

        EntityTransaction userTransaction = em.getTransaction();
        userTransaction.begin();
        UserProfile userProfile = em.find(UserProfile.class,"1");

        if(userProfile.getUserId().equals("tok"))
        {
            System.out.println("find");
            System.out.println("write successful");
        }


        entityManagerFactory.close();


    }
}

My Spring injection that does not work.
I had injected UserProfile entity using setters but i think there is a problem because it could not retrieve any data.

private UserProfile userProfile; --> it does inject.

entityStart.em.find(UserProfile.class, userId)--> will not work in the sense that no values are retrieved.

Complete Class

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lotmovement.business.crud;

import lotmovement.business.entity.UserProfile;

/**
 *
 * @author god-gavedmework
 */
public class RecordExistUserProfile {

    private EntityStart entityStart;
    private UserProfile userProfile;


    public boolean checkrecordexist(String userId) {
        entityStart.StartDbaseConnection();
        entityStart.em.find(UserProfile.class, userId); ---> this one will not work.

        if (userId.equals(userProfile.getUserId())) {
            return true;
        } else {
            return false;
        }
    }

    public boolean CheckPasswordCorrect(String userId, String password) {
        entityStart.StartDbaseConnection();

        UserProfile up = entityStart.em.find(UserProfile.class, userId); --> this one will work but it is not injected...


        if (password.equals(up.getPassword())) {
            return true;
        } else {
            return false;
        }

    }



    public UserProfile getUserProfile() {
        return userProfile;
    }

    public void setUserProfile(UserProfile userProfile) {
        this.userProfile = userProfile;
    }

    public EntityStart getEntityStart() {
        return entityStart;
    }

    public void setEntityStart(EntityStart entityStart) {
        this.entityStart = entityStart;
    }



}
  • 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-15T20:33:32+00:00Added an answer on June 15, 2026 at 8:33 pm

    Finally I found the root cause and the solution of the problem.

    Root Cause:

    UserProfile userProfile; –> it will inject the UserProfile entity.

    entityStart.em.find(UserProfile.class, userId); –> This will not work because the it was not passed to the class variable userProfile..

    Solution:

    UserProfile userProfile; –> inject the UserProfile entity.

    userProfile = entityStart.em.find(UserProfile.class, userId); —> find() now works find.

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

Sidebar

Related Questions

How can I inject a property to a class I don't have access to
I have a Spring Project with Wicket. I can successfully inject Services in Wicket
I'm using Tomcat 6.0.33 with Java 6. I have this servlet ... public class
Using Guice, I want to inject a bounded-wildcard class. To be clear, I don't
Can anyone explain this to me. I'm trying to inject a CSS file onto
When using Ninjects ConstructorArgument you can specify the exact value to inject to specific
Can I order my users in the database, so I don't have to say
I have a logger interface that I inject into many different classes, can I
I have a strange problem. Afaik I can inject a SessionScoped bean into a
In my Silverlight RIA app I can successfully inject an ExceptionHelper class via constructor

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.