IntelliJ giving me error message on Spring, WebFlow project which works and Eclipses dont give error

IntelliJ giving me error message on Spring, WebFlow project which works and Eclipses dont give error.

This is the error I am getting:
Could not autowire. There is more than one bean of 'SessionFactory' type. Beans: sessionFactory,sessionFactory. less... (Ctrl+F1)
Checks autowiring problems in a bean class.

Here is the source to the class:
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.uftwf.core.model.Profile;
import org.uftwf.core.model.School;
import org.uftwf.enrollment.domain.Member;
import org.uftwf.enrollment.exception.AS400Exception;
import org.uftwf.enrollment.model.Enrollment;
import org.uftwf.enrollment.storedproc.EnrollmentProcedure;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Last changed: $LastChangedDate: 2012-10-22 09:20:51 -0400 (Mon, 22 Oct 2012)
* $
*
* @author xxxx
* @version $Revision$
*/

@Repository
public class EnrollmentDaoImpl implements BeanFactoryAware, EnrollmentDao {

    @Autowired
    protected SessionFactory sessionFactory;
    //
    // this is for a test of my idea
    //

    private static Log LOGGER = LogFactory
            .getLog(EnrollmentDao.class.getName());

    private BeanFactory beanFactory;

    public EnrollmentDaoImpl() {
        super();
        LOGGER = LogFactory.getLog(EnrollmentDaoImpl.class);

    }



    @Transactional(readOnly = true, propagation = Propagation.REQUIRED)
    public void saveMember(Member member) {
        Session mySession = sessionFactory.getCurrentSession();
        //
        // Get profile record based on email address
        //
        Profile myProfile = (Profile) mySession.createCriteria(Profile.class)
                .add(Restrictions.like("email", member.getEmail())).uniqueResult();
        //
        // Start to create a new Enrollment Record with a status of "U"
        //
        Enrollment newEnrollment = new Enrollment();
        newEnrollment.setCurrent_status("M");
        //
        // From Profile
        //
        newEnrollment.setProfile_id(myProfile.getProfileID());
        newEnrollment.setContact_id(myProfile.getContactID());
        //
        // From Screen
        //
        newEnrollment.setEnrollment_type_id(member.getEnrollment_type().toUpperCase()+ "");
        newEnrollment.setFile_num(member.getFile_num().toUpperCase()+ "");
        newEnrollment.setSsn(member.getFullSSN()+ "");
        newEnrollment.setFirst_name(member.getFirst_name().toUpperCase() + "");
        newEnrollment.setLast_name(member.getLast_name().toUpperCase() + "");
        newEnrollment.setMiddle_initial(member.getMiddle_initial().toUpperCase() + "");
        newEnrollment.setSchool_id(member.getSchool().toUpperCase() + "");
        newEnrollment.setBorough_id(member.getBorough().toUpperCase() + "");
        newEnrollment.setEis_num(member.getEis_num().toUpperCase() + "");
        //
        // Setting time currentTime
        //
        String currentTime = getCurentTime();
        newEnrollment.setLast_update(currentTime);
        newEnrollment.setEntry_date(currentTime);
        //
        // Saving to database
        //
        mySession.save(newEnrollment);
        mySession.flush();
    }


    private String getCurentTime()
    {
        Date dt = new Date();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(dt);
    }

    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
    public void saveToPending(Member member) {
        Session mySession = sessionFactory.getCurrentSession();


        //
        // Get profile record based on email address
        //

        Profile myProfile = (Profile) mySession.createCriteria(Profile.class)
                .add(Restrictions.like("email", member.getEmail())).uniqueResult();

        //
        // Start to create a new Enrollment Record with a status of "U"
        //

        Enrollment newEnrollment = new Enrollment();
        newEnrollment.setCurrent_status("U");

        //
        // From Profile
        //

        newEnrollment.setProfile_id(myProfile.getProfileID());
        newEnrollment.setContact_id(myProfile.getContactID());

        //
        // From Screen
        //
        newEnrollment.setEnrollment_type_id(member.getEnrollment_type().toUpperCase()+ "");
        newEnrollment.setFile_num(member.getFile_num().toUpperCase()+ "");
        newEnrollment.setSsn(member.getFullSSN()+ "");
        newEnrollment.setFirst_name(member.getFirst_name().toUpperCase() + "");
        newEnrollment.setLast_name(member.getLast_name().toUpperCase() + "");
        newEnrollment.setMiddle_initial(member.getMiddle_initial().toUpperCase() + "");
        newEnrollment.setSchool_id(member.getSchool().toUpperCase() + "");
        newEnrollment.setBorough_id(member.getBorough().toUpperCase() + "");
        newEnrollment.setEis_num(member.getEis_num().toUpperCase() + "");


        //
        // Setting time currentTime
        //
        String currentTime = getCurentTime();
        newEnrollment.setLast_update(currentTime);
        newEnrollment.setEntry_date(currentTime);


        //
        // Saving to database
        //
        mySession.save(newEnrollment);
        mySession.flush();
    }

    @Transactional(readOnly = true, propagation = Propagation.REQUIRED)
    private String getProfileNumber(String email) {
        LOGGER.debug("[" + email + "]");
        Session mySession = sessionFactory.getCurrentSession();
        /*
         * Getting profile information
         */
        Profile myProfile = (Profile) mySession.createCriteria(Profile.class)
                .add(Restrictions.like("email", email)).uniqueResult();
        LOGGER.debug("[" + myProfile.toString() + "]");
        return myProfile.getProfileID() + "";
    }

    @Transactional(readOnly = true, propagation = Propagation.REQUIRED)
    public boolean isPending(String email) {

        String profile_id = getProfileNumber(email);
        LOGGER.debug("Profile ID = [" + profile_id + "]");

        Session mySession = sessionFactory.getCurrentSession();

        /*
         * Getting profile information
         */


        try {
            Enrollment myEnrollment = (Enrollment) mySession
                    .createCriteria(Enrollment.class)
                    .add(Restrictions.like("profile_id", profile_id))
                    .uniqueResult();

            if (myEnrollment != null) {
                LOGGER.debug("[" + myEnrollment.toString() + "]");
                return myEnrollment.getCurrent_status().equalsIgnoreCase("U");

            } else {
                return false;
            }
        } catch (HibernateException e) {
            LOGGER.error("Profile ID = [" + profile_id + "] has dupped rows in enrollment");
            return true;
        }
    }


    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;

    }

    public String checkStatus(Member member) throws AS400Exception {
        Map<String, Object> resultSet;
        String returncode;

        try {
            EnrollmentProcedure myos400StoredProcedure = (EnrollmentProcedure) beanFactory
                    .getBean("checkStatusStoredProcedure");

            Map<String, Object> cs = new HashMap<String, Object>();

            LOGGER.debug("checkStatus:" + member.toString());

            cs.put("param2", member.getEnrollment_type().toUpperCase());
            cs.put("param3", member.getFirst_name().toUpperCase());
            cs.put("param4", member.getLast_name().toUpperCase());
            cs.put("param5", member.getMiddle_initial().toUpperCase());
            cs.put("param6", member.getFullSSN().toUpperCase());
            cs.put("param7", member.getFile_num().toUpperCase());
            cs.put("param8", member.getEis_num().toUpperCase());

            resultSet = myos400StoredProcedure.executeStoredProcedure(cs);

            if (resultSet.isEmpty()) {
                LOGGER.error("iSeries returned no values.");
                throw new AS400Exception(
                        "AS/400 Returned No Values for SSN Check");
            } else {

                BigDecimal MBSID = (BigDecimal) resultSet.get("memberId");

                member.setMBSMemberID(MBSID);

                returncode = ((String) resultSet.get("mbsReturnCode")).trim();

                LOGGER.debug("Return Code from (checkStatusStoredProcedure):"
                        + returncode);
            }

        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            throw new AS400Exception(e.getMessage());
        }

        return returncode;
    }

    public boolean isSSNOnFile(Member member) throws AS400Exception {

        Map<String, Object> resultset;

        try {
            EnrollmentProcedure myos400StoredProcedure = (EnrollmentProcedure) beanFactory
                    .getBean("isSSNonFileStoredProcedure");

            Map<String, Object> cs = new HashMap<String, Object>();
            //
            // Moving data to proc.
            // based on jimmy i only pass ssn

            cs.put("param2", "");
            cs.put("param3", "");
            cs.put("param4", "");
            cs.put("param5", "");
            cs.put("param6", member.getFullSSN().toUpperCase());
            cs.put("param7", "");
            cs.put("param8", "");

            resultset = myos400StoredProcedure.executeStoredProcedure(cs);

            if (resultset.isEmpty()) {
                LOGGER.error("iSeries returned no values.");
                throw new AS400Exception(
                        "AS/400 Returned No Values for SSN Check");
            } else {
                String returncode = (String) resultset.get("mbsReturnCode");

                LOGGER.debug("Return Code from (isSSNonFileStoredProcedure):"
                        + returncode);

                if (returncode.trim().equalsIgnoreCase("RTN06")) {
                    LOGGER.debug("Returning Good SSN");
                    return true;
                }

                if (returncode.trim().equalsIgnoreCase("RTN02")) {
                    LOGGER.debug("Returning NOT SSN");
                    return false;
                }
            }

        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            throw new AS400Exception(e.getMessage());
        }

        return false;
    }

    public String getEnrollmentDates(Member member) throws AS400Exception {
        Map<String, Object> resultSet;
        String returncode;

        try {
            EnrollmentProcedure myos400StoredProcedure = (EnrollmentProcedure) beanFactory
                    .getBean("getEnrollmentDateProcedure");

            Map<String, Object> cs = new HashMap<String, Object>();

            LOGGER.debug("getEnrollmentDateProcedure:" + member.toString());

            cs.put("param2", 1);
            cs.put("param3", member.getMBSMemberID());

            resultSet = myos400StoredProcedure.executeStoredProcedure(cs);

            if (resultSet.isEmpty()) {
                LOGGER.error("iSeries returned no values.");
                throw new AS400Exception(
                        "AS/400 Returned No Values for Holding Period Check");
            } else {

                member.setActiveEnrollmentDate(resultSet.get("ActiveEnrolDate")
                        + "");
                member.setRetiredEnrollmentDate(resultSet
                        .get("RetiredEnrolDate") + "");

                returncode = (String) resultSet.get("ReturnCode");

                LOGGER.debug("Return Code from (getHoldingPeriodProcedure):"
                        + returncode);
            }

        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            throw new AS400Exception(e.getMessage());
        }

        return returncode;
    }

    public String getHoldingPeriod() throws AS400Exception {
        Map<String, Object> resultSet;
        String returncode;

        try {
            EnrollmentProcedure myos400StoredProcedure = (EnrollmentProcedure) beanFactory
                    .getBean("getHoldingPeriodProcedure");

            Map<String, Object> cs = new HashMap<String, Object>();

            cs.put("param2", 1);
            cs.put("param3", "MB");
            cs.put("param4", "UEPARM");

            resultSet = myos400StoredProcedure.executeStoredProcedure(cs);

            if (resultSet.isEmpty()) {
                LOGGER.error("iSeries returned no values.");
                throw new AS400Exception(
                        "AS/400 Returned No Values for Holding Period Check");
            } else {

                BigDecimal hp = (BigDecimal) resultSet.get("HoldingPeriod");

                returncode = hp.toString();

                LOGGER.debug("Return value from (getHoldingPeriodProcedure):"
                        + returncode);
            }

        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            throw new AS400Exception(e.getMessage());
        }

        return returncode;

    }

}



Can someone please tell me why the IDEA would be getting me a error on the Autowired in this class?

7 comments

What version of IntelliJ IDEA are you using? Could you please describe your Spring setup and show your Spring facet setup? Thanks.

0

I am using IntelliJ U 12.0.4, I dont understant what you mean about  "describe your Spring setup" or how can "show your Spring facet setup"

anyway to send you the files off line>

0

You can upload your project to ftp://ftp.intellij.net/.uploads/ and tell me filename (only JB employees can access files on FTP).

0

You'll need to use an FTP client. You can also upload it anywhere else (DropBox, any filesharing service, ...) and mail me URL (yann.cebron@jetbrains.com)

0

thanks.. I emailed you a dropbox request.. do you have assembla.com or any other free private git repo

0

The error you are getting means that you have more than one "live" definition of the SessionFactory instance in your Spring application ocntext. You may have several spring XML files where a SessionFactory is defined, an al those files are included in the overalll application context for the project. It may be not happenning at runtime, but depending on how your IntelliJ project is configured, IDEA may consider all those config files when resolving dependencies in the editor on the fly. For example, you may have a test config file somewhere that IDEA sees in the classpath, etc.

Off topic...  Reconsider your exception handling. Don't ever rethrow an exception without nesting the original "cause" exception, you are losing a ton of useful info. The ex.getMessage() may be meaningless, but all the useful error info is actually in the stack trace. Also, all static variables should be final, e.g. your logger. Good luck...  

0

Please sign in to leave a comment.