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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:38:25+00:00 2026-05-20T08:38:25+00:00

I have entity class which is used to model a weather station, and it

  • 0

I have entity class which is used to model a weather station, and it includes a unique string property “code”. I also have an entity class which is used to contain daily averages for various observations, and this daily average entity class has an many-to-one association to the station entity class, i.e. each daily average object is associated with a station:

@Entity(name = EsrlDailyAvg.TABLE_NAME)
@Table(name = EsrlDailyAvg.TABLE_NAME, 
       uniqueConstraints = { @UniqueConstraint(columnNames = { EsrlDailyAvg.STATION_COLUMN_NAME,
                                                               EsrlDailyAvg.DATE_COLUMN_NAME }) })
public final class EsrlDailyAvg
    extends AbstractPersistentEntity<Long>
{
    public static final String TABLE_NAME = "ESRL_DAILY_AVG";
    public static final String STATION_COLUMN_NAME = "ESRL_STATION_ID";
    public static final String DATE_COLUMN_NAME = "ESRL_DATE";
    private EsrlStation station;
    private Date date;
    // additional properties used to contain average values

    @Column(name = DATE_COLUMN_NAME, nullable = false)
    public Date getDate()
    {
        return date;
    }

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
    @JoinColumn(name = STATION_COLUMN_NAME)
    public EsrlStation getStation()
    {
        return station;
    }

    ....
}


@Entity(name = EsrlStation.TABLE_NAME)
public class EsrlStation
    extends AbstractPersistentEntity<Long>
{
    public static final String TABLE_NAME = "ESRL_STATION";
    private EsrlStationCodeEnum code;

    @Column(name = "CODE", nullable = false, unique = true)
    @Enumerated(EnumType.STRING)
    public EsrlStationCodeEnum getCode()
    {
        return code;
    }

    ...
}

The DAO class for daily average entities contains a method to find a unique daily average entity by station code and date:

public EsrlDailyAvg findByStationCodeDate(final String stationCode,
                                          final Date date)
{
    String hql = "from " + getCanonicalPersistentClassName() + " dailyAvg where dailyAvg.station.code = '" +
                 stationCode + "' and dailyAvg.date = :date";
    return (EsrlDailyAvg) getCurrentSession().createQuery(hql).setParameter("date", date).uniqueResult();
}

I have written tests which save and then successfully find daily average entities by station code and date, so I am assuming that the above DAO code works as expected. However when I run a stand-alone program which uses this DAO method I cannot successfully find a daily average entity object which I know to be present (I can query the database using SQL and see the record).

I’m not sure if this is relevant but I run my tests using an in-memory HSQL database, and I am running the stand-alone program using an Oracle database.

I have debugged the code and the station code and date parameters are being passed as expected to the DAO method.

Can anyone comment as to why this is happening, or suggest where I should look for the error? Thanks in advance for your help.

  • 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-20T08:38:26+00:00Added an answer on May 20, 2026 at 8:38 am

    It turns out that the error had to do with how I was creating the date parameter that was being passed to the DAO method in question. I was first creating a GregorianCalendar object in order to set the year, month, and day, but I neglected to set the milliseconds field value to zero. Once I did that then the Date value that I used as the parameter to the DAO method (myCalendar.getTime()) matches to the date value in the database and the DAO method finds the record as expected.

    Lesson learned: when deriving a Date from a Calendar be sure to set all of the Calendar fields (don’t assume zero values for unset Calendar fields).

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

Sidebar

Related Questions

I have an entity class that has a property with an underlying db column
I have a collection of custom entity objects one property of which is an
So long story short I have an object model in which several different entity
Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I have the following entity class (in Groovy): import javax.persistence.Entity import javax.persistence.Id import javax.persistence.GeneratedValue
I have the following entity structure: public class Party { public Int32 PartyId {
I have an entity that maps to an external oracle table which is one
In my Core Data managed object model, I have an entity Foo with a
I have a wpf window which is used to add as well as edit
As I have understood MVC, the logic for the model should also go into

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.