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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:15:29+00:00 2026-05-25T21:15:29+00:00

I’m sure this has been encountered many times over, and written about elsewhere. Apologies

  • 0

I’m sure this has been encountered many times over, and written about elsewhere. Apologies in advance for the long-winded post, but I wanted to provide as much detail as I could up front.

I have a workstation running the JVM in one timezone (in my case -07:00). I have an Oracle database configured to persist date values in UTC.

I am attempting to use jodatime extension, http://www.joda.org/joda-time-hibernate/, that has custom Hibernate types, one of which is PersistentDateTime.

Here is a sample from my .hbm.xml.

<hibernate-mapping>
<class name="com.spp.mui.domain.MktBidHourly" table="MKTBIDHOURLY">
    <comment>Entity to represent the hourly participant bids</comment>
    <id name="bidId" type="big_decimal">
        <column name="BIDID" precision="22" scale="0" />
        <generator class="foreign">
            <param name="property">mktBid</param>
        </generator>
    </id>
    <one-to-one name="mktBid" class="com.spp.mui.domain.MktAbstractBid" constrained="true"></one-to-one>

    <property name="period" type="org.joda.time.contrib.hibernate.PersistentDateTime">
        <column name="PERIOD" length="7">
            <comment>Identifies the Period for which the bid applies.</comment>
        </column>
    </property>
    <property name="bidCurveId" type="big_decimal">
        <column name="BIDCURVEID" precision="22" scale="0">
            <comment>A database-generated unique identifier for the bid curve</comment>
        </column>
    </property>
</class>

Note the period field in MktBidHourly.

So before executing a unit test for one of my DAOs (using Spring), I use a tool like Toad (for Oracle), to insert some data, that will be queried in the test, something like

insert into MKTBIDHOURLY values (33, (select to_timestamp(‘2011-08-03
13:00’, ‘YYYY-MM-DD HH24:MI’) from dual), 298384);

The Hibernate query in my DAO looks a little like this

public static final String QRY_FIND_BIDS =
        "from MktBid bid where bid.priceNodeId in (:priceNodeIdList) and bid.mktBidHourly.period in (:periodsList) and bid.mktBidType = (:bidType) and bid.participantId = (:participantId)";

 Query q = getSession().createQuery(MktQueries.QRY_FIND_BIDS);
        q.setParameterList("priceNodeIdList", priceNodeIds);
        q.setParameterList("periodsList", periods);
        q.setEntity("bidType", bidType);
        q.setBigDecimal("participantId", participantId);
        realBids = q.list();

Here’s the test method

@Test
public void testFindVirtualBids() throws ParseException {
    List<MktVirtualBid> candidateBids = new ArrayList<MktVirtualBid>();
    MktBidType bidType = new MktBidType(MktBid.VIRTUAL_BID);
    candidateBids.add(data.createMktVirtualBid(new BigDecimal(LOCATION_ID_1), false, timeDispatcher.getDateTimeFromXMLDateTime("2011-08-03T13:00:00-07:00"), new BigDecimal(CURVE_ID_1)));
    candidateBids.add(data.createMktVirtualBid(new BigDecimal(LOCATION_ID_2), false, timeDispatcher.getDateTimeFromXMLDateTime("2011-08-04T13:00:00-07:00"), new BigDecimal(CURVE_ID_2)));
    List<MktVirtualBid> foundBids = dao.findVirtualBids(bidType, new BigDecimal(PARTICIPANT_ID), candidateBids);
    Assert.assertEquals(2, foundBids.size());
}

Note the timeDispatcher method is using

ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.getDefault())

as formatter, and then

parseDateTime(xmlDateTime).withZone(DateTimeZone.UTC)

to obtain a DateTime.

Here’s some sample output from a test run (sorry for the poor formatting)

16:22:31,729 DEBUG [AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
16:22:31,732 DEBUG [SQL]
select
mktbid0_.BIDID as BIDID5_,
mktbid0_.BIDTYPE as BIDTYPE5_,
mktbid0_.PARTICIPANTID as PARTICIP3_5_,
mktbid0_.PNODEID as PNODEID5_,
mktbid0_.USEBIDSLOPE as USEBIDSL5_5_
from
DEVMOI2.MKTBID mktbid0_,
DEVMOI2.MKTBIDHOURLY mktbidhour1_
where
mktbid0_.BIDID=mktbidhour1_.BIDID
and (
mktbid0_.PNODEID in (
? , ?
)
)
and (
mktbidhour1_.PERIOD in (
? , ?
)
)
and mktbid0_.BIDTYPE=?
and mktbid0_.PARTICIPANTID=? Hibernate:
select
mktbid0_.BIDID as BIDID5_,
mktbid0_.BIDTYPE as BIDTYPE5_,
mktbid0_.PARTICIPANTID as PARTICIP3_5_,
mktbid0_.PNODEID as PNODEID5_,
mktbid0_.USEBIDSLOPE as USEBIDSL5_5_
from
DEVMOI2.MKTBID mktbid0_,
DEVMOI2.MKTBIDHOURLY mktbidhour1_
where
mktbid0_.BIDID=mktbidhour1_.BIDID
and (
mktbid0_.PNODEID in (
? , ?
)
)
and (
mktbidhour1_.PERIOD in (
? , ?
)
)
and mktbid0_.BIDTYPE=?
and mktbid0_.PARTICIPANTID=?
16:22:31,733 TRACE [AbstractBatcher] preparing statement
16:22:31,798 TRACE [BasicBinder] binding parameter [1] as [NUMERIC] – 262235
16:22:31,798 TRACE [BasicBinder] binding parameter [2] as [NUMERIC] – 262234
16:22:31,799 TRACE [BasicBinder] binding parameter [3] as [TIMESTAMP] – Wed Aug 03 13:00:00 PDT 2011
16:22:31,799 TRACE [BasicBinder] binding parameter [4] as [TIMESTAMP] – Thu Aug 04 13:00:00 PDT 2011
16:22:31,801 TRACE [BasicBinder] binding parameter [5] as [VARCHAR] – D
16:22:31,801 TRACE [BasicBinder] binding parameter [6] as [NUMERIC] – 260699

and then the test fails

Results :

Failed tests:
testFindVirtualBids(com.spp.mui.persistence.hibernate.MktBidDAOTest): expected:<2> but was:<0>

Tests run: 2, Failures: 1, Errors: 0, Skipped: 0

Why won’t my test’s assertion pass?

  • 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-25T21:15:30+00:00Added an answer on May 25, 2026 at 9:15 pm

    I solved this myself. The tricky part in how I was inserting dates. I opted for another route, which unfortunately I cannot share the code for. Suffice it to say I developed a test base class with a routine for loading in CSV files. It leverages Spring’s TestContext framework, particularly an @BeforeTransaction annotated method which delegates to helpers to deal with various String types (e.g., date, number, byte[], etc).

    The formatter is fundamentally correct. For those who are curious The timeDispatcher’s method impl looks like this…

     public DateTime getDateTimeFromXMLDateTime(String xmlDateTime) {  
        if(xmlDateTime == null || "".equals(xmlDateTime)) {  
            return null;  
        } else {  
            return isoParser.parseDateTime(xmlDateTime).withZone(gmtTZ);  
        }  
    }  
    

    where

    isoParser = ISODateTimeFormat.dateTimeParser(DateTimeZone.getDefault());  
    

    and

    gmtTZ = DateTimeZone.UTC;  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

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.