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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:57:58+00:00 2026-05-12T07:57:58+00:00

I have problem when want read object with where (double variable) this is my

  • 0

I have problem when want read object with where (double variable)
this is my Code :

BranchBuilding Table:

@Entity
@Table(name = "branchbuilding", uniqueConstraints={@UniqueConstraint(columnNames={"buildingname","branch_fk"})})//uniqueConstraints={@UniqueConstraint(columnNames={"username","buildingname"})}
public class BranchBuildingEntity implements Serializable {

    @Id
    @GeneratedValue
    private int id;
    @Column(name = "buildingname", length = 64)
    private String buildingName;
    @Column(name = "description", columnDefinition = "mediumtext", length = 16777215)
    private String description;
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(name = "bremainAdr", column = @Column(name = "bremainadr", columnDefinition = "mediumtext", length = 16777215, nullable=true)),
        @AttributeOverride(name = "bmainStreet", column = @Column(name = "bmainstreet", length = 64, nullable=true)),
        @AttributeOverride(name = "bstate", column = @Column(length = 64, nullable=true)),
        @AttributeOverride(name = "bcity", column = @Column(length = 64, nullable=true)),
        @AttributeOverride(name = "bcentralBuilding", column = @Column(name = "bcentralbuilding", columnDefinition = "tinyint", nullable=true)),
        @AttributeOverride(name = "blongitude", column = @Column(nullable=true)),
        @AttributeOverride(name = "blatitude", column = @Column(nullable=true))
    })
    Address buildingAdr;
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "branch_fk", referencedColumnName = "id", nullable = false)
    private BranchEntity branch;

    @OneToMany(mappedBy = "branchbuilding", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @OnDelete(action=OnDeleteAction.CASCADE)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private Set<BuildingTelEntity> buildingtel = new HashSet<BuildingTelEntity>();
//some setter and getter

Adrresse Embbedable:

@Embeddable
public class Address implements Serializable {

    String bstate;
    String bcity;
    String bmainStreet;   
    String bremainAdr;
    double blongitude;
    double blatitude;
    int bcentralBuilding;
//Some getter and Setter

this is my Query Manager:

public List<T> executeQuery(String query, Object... values) throws DatabaseException {
        logger.info("it's at the first of executeQuery(String query, Object... values)");
        List<Object> ret;
        Session sess = null;
        boolean freed = false;
        List<T> result;
        try {
            sess = HibernateUtil.getSession();
            Transaction tx = sess.beginTransaction();
            Query q = sess.createQuery(query);
            for (int i = 0; i < values.length; i++) {
                if (values[i].getClass().getSimpleName().equals("Long")) {
                    q.setLong(i, (Long) values[i]);
                } else if (values[i].getClass().getSimpleName().equals("String")) {
                    q.setString(i, (String) values[i]);
                } else if (values[i].getClass().getSimpleName().equals("Integer")) {
                    q.setInteger(i, (Integer) values[i]);
                } else if (values[i].getClass().getSimpleName().equals("Double")) {
                    q.setDouble(i, (Double) values[i]);
                } else if (values[i].getClass().getSimpleName().equals("Boolean")) {
                    q.setBoolean(i, (Boolean) values[i]);
                } else {
                    q.setEntity(i, values[i]);
                }
            }
            ret = q.list();
            tx.commit();
            result = makeClass(ret);
            HibernateUtil.freeSession(sess);
            freed = true;
        } catch (HibernateException e) {
            logger.error("Hibernate Exception occurred in executeQuery() Method", e);
            e.printStackTrace();
            if (!freed && sess != null) {
                HibernateUtil.freeSession(sess);
            }
            throw new DatabaseException("Can not execute query.");
        } catch (Exception e) {
            logger.fatal("Exception occurred in executeQuery() Method", e);
            System.out.println(e.getMessage());
            throw new DatabaseException("Can not execute query.");
        }

        return result;
    }

this is a class maker:

 private List<T> makeClass(List<Object> input) {
        List<T> ret = new ArrayList<T>();
        int size = input.size();
        for (int i = 0; i < size; i++) {
            T curr = (T) input.get(i);
            ret.add(curr);
        }
        return ret;
    }

i want load a buildingBranch entity by it’s Geographical coordinate but when I set Query
it’s retun null.

 return queryManager.executeQuery("from BranchBuildingEntity b where b.buildingAdr.blongitude = 51.6371154785156 AND b.buildingAdr.blatitude = 35.658412064282"); 

or

 return queryManager.executeQuery("from BranchBuildingEntity b where b.buildingAdr.blongitude = ? AND b.buildingAdr.blatitude = ?", longit, latid);//longit and latid both are double 

but when I use Query Below it’s return a correct result(I Insertsome branchbuilding by lat = 0 and long = 0 in my table)

return queryManager.executeQuery("from BranchBuildingEntity b where b.buildingAdr.blongitude = 0.0 AND b.buildingAdr.blatitude = 0.0"); 

any body know where is my Problem?

  • 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-12T07:57:59+00:00Added an answer on May 12, 2026 at 7:57 am

    As David M says, don’t do direct comparison of doubles. Either use a different representation or do an indirect comparison :

    abs(b.buildingAdr.blongitude - 51.6371154785156) < threshold
    

    The threshold value dictates how close two longitudes have to be (numerically) to be considered to be the same. So you pick a value for threshold that works best for you (e.g. 0.000000001).

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

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How about adding this to .emacs, setting up a macro… May 12, 2026 at 11:02 pm
  • Editorial Team
    Editorial Team added an answer Make sure you are picking the relationship arrow from the… May 12, 2026 at 11:02 pm
  • Editorial Team
    Editorial Team added an answer The difference is that recv()/send() work only on socket descriptors… May 12, 2026 at 11:02 pm

Related Questions

I am working on a VB6 application that uses an ADODB.Recordset object to dump
I want to load a list of records given a possibly lengthy list of
We're planning to create a web application where users can build custom forms, choosing
I wrote a file parser for a game I'm writing to make it easy

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.