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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:01:24+00:00 2026-06-15T23:01:24+00:00

CustomerSurvey.java public class CustomerSurvey implements Serializable { /** * */ private static final long

  • 0

CustomerSurvey.java

 public class CustomerSurvey
    implements Serializable
 {

/**
 * 
 */
private static final   long  serialVersionUID = 1L;

@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CUSTOMER_SURVEY_SEQUENCE") @Column(name = "SURVEYID", nullable = false) private String surveyId;

@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn(name = "CUSTNO", referencedColumnName = "CustNO") private Customer               customer;
@Column(name = "AVGRATINGS") private double                                                                                                                 avgRatings;

@Column(name = "COMMENTS") private String                                                                                                                   comments;

@Column(name = "SENTON") private Date                                                                                                                       sentOn;

@Column(name = "RESPONDEDON") private Date                                                                                                                  respondedOn;

@Column(name = "RESPONDED") int                                                                                                                             responded;
@Basic(fetch = FetchType.EAGER) @OneToMany(mappedBy = "customerSurvey", cascade = CascadeType.ALL) private Set<SurveyResponse>                              responses;

@XmlTransient @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.DETACH) @JoinColumn(name = "SRNO") private ServiceRequest                             serviceRequest;

@Column(name = "ATTACHMENT") @Lob @Basic(fetch = FetchType.EAGER) private byte[]                                                                            attachment;
--- getters and setters---

 public int hashCode()
     {
    return new HashCodeBuilder(17,31)
    .append(this.surveyId)
 //        .append(this.avgRatings)
 //        .append(this.getResponded())
    .toHashCode();

}

@Override
public boolean equals(Object obj)
{

    return new EqualsBuilder().
            append("SurveyId",this.surveyId)
//                .append("responded", this.getResponded())
//                .append("AvgRatings", this.getAvgRatings())
            .isEquals();
}

Persistence Code:
public void submitSurveyResponse(List surveys)
throws WorkServiceException
{

    if ( this.entityManagerFactory == null )
    {
        this.entityManagerFactory = this.getEntityManagerFactory();
    }

    EntityManager em = this.entityManagerFactory.createEntityManager();
    EntityTransaction tx = em.getTransaction();

    for (CustomerSurvey survey : surveys)
    {
        tx.begin();
        survey.setRespondedOn(Calendar.getInstance().getTime());
        survey.setResponded(BooleanResponse.YES.getCode());
        survey.setCustomer(em.find(Customer.class, survey.getCustomer().getCustNo().trim()));
        survey.setComments("Survey Response submitted");
        for (SurveyResponse response : survey.getResponses())
        {
            response.setQuestionair(em.find(Questionair.class, response.getQuestionair().getqNo()));
        }

        CustomerSurvey cs = em.find(CustomerSurvey.class, survey.getSurveyId());
        System.out.println(survey.equals(cs));
        Query query1 = em.createQuery("SELECT  from CustomerSurvey customerSurvey where customerSurvey.surveyId = :id")
                .setParameter("id", survey.getSurveyId());
        CustomerSurvey dbSurvey = (CustomerSurvey) query1.getResultList().get(0);
        System.out.println(":" + survey.equals(dbSurvey));

        if(survey.getServiceRequest() == null) {
            cs = em.find(CustomerSurvey.class, survey.getSurveyId());
            survey.setServiceRequest(cs.getServiceRequest());
        }
        CustomerSurvey mSurvey = em.merge(survey);

        String surveyId = mSurvey.getSurveyId();
        Query query = em.createNamedQuery("surveyResponse.getAverageRatings");
        logger.trace(query.toString());
        query.setParameter("surveyId", surveyId);
        logger.trace(query.toString());

        Double avgRating = (Double) query.getSingleResult();
        if ( avgRating == null )
        {
            avgRating = new Double(0);
        }
        BigDecimal bd = BigDecimal.valueOf(avgRating);
        bd = bd.setScale(2, RoundingMode.HALF_UP);
        avgRating = bd.doubleValue();
        mSurvey.setAvgRatings(avgRating);
        em.flush();
        tx.commit();
   }
    em.clear();
    em.close();
}

It does not update , instead it inserts new row.
After using hashcode builder and equals builder I get false for folloing check:
The test for System.out.println(“:” + survey.equals(dbSurvey)); gives false
The test for System.out.println(survey.equals(cs));
above gives false.

please advice

  • 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-15T23:01:25+00:00Added an answer on June 15, 2026 at 11:01 pm

    “transient” and “detached” are different states and will have different behaviour in merge() as per the JPA spec. transient will create a new object. detached with update an existing. Either obtain a detached object before modifying it, or read the section “Detachment” on http://www.datanucleus.org/products/accessplatform_3_2/jpa/object_lifecycle.html

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

Sidebar

Related Questions

Entity class: public class CustomerSurvey implements Serializable { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator=CUSTOMER_SURVEY_SEQUENCE) @Column(name = SURVEYID,
Helo, there are 3 files, CustomerClient.java , CustomerServer.java and Customer.java PROBLEM: In the CustomerServer.java
I have detached all entities with em.clear() but I do not see the associated
I am concerned with the performance of a database table i have to store
Following is the table structure: desc customer_survey Name Null Type ----------- -------- ------------ SURVEYID
I am going to develop a mobile application used by our company salesmen to
@model SA.MarketingManager.WebClient.Areas.Reports.Models.ViewReportModel @{ Layout = ~/CustomViews/lennoxcap.net/Shared/_DealerLayout.cshtml; } @using (Html.BeginForm()) { <div style=width: 100%; font-size:
I had a design dilemma , suffering from my lack of experience I have
I'm creating a customer survey using a jQuery UI dialog. I'm loading an external
I'm playing around with EF4.1 in a Visual C# 2010 Express project and I

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.