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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:59:02+00:00 2026-05-24T06:59:02+00:00

I recently replaced PostgreSql unit test database with an in memory H2 Database. I

  • 0

I recently replaced PostgreSql unit test database with an in memory H2 Database. I couldn’t figure out why couple tests are failing, it was working fine with Postgre. There are approx. 280+ unit tests in this application. The failing dao tests are selecting from a view and the entity has a EmbeddedId, those the columns of that view.
See below code (Note: I changed names, code and the sql to hide the real names when writing this email, but this was a working unit test with Postgre db)

<pre>

@Table(name = "item_view") // <- item_view is a database view
public class ItemV implements Serializable
{
    .....
    @EmbeddedId // <- entity has an embedded id
    private ItemVId id;  
    .....

@Embeddable
    public static class ItemVId implements Serializable //<- This is the embeddedId
    {
        @Column(name = "item_id", updatable=false, insertable=false)
        private Long ItemId; //<- col no.1 of view

        @Column(name = "item_type_id", updatable=false, insertable=false)
        private Integer ItemTypeId; //<- col no.2 of view
    .....       
ItemType is an enum

And the view is
CREATE OR REPLACE VIEW item_view AS 
        (        (        (         SELECT pt.id as item_id, cit.id as item_type_id
                                   FROM xyz pt, item_type cit
                                  WHERE pt.name::text = 'xyz'::text
                        UNION 
                                 SELECT z.id as item_id, cit.id as item_type_id
                                   FROM zzz z, item_type cit
                                  WHERE z.name::text = 'zzz'::text)
                ..............

and the dao method is

    public ItemView find(Long itemId, ItemType itemType)
    {
        String hql = " from ItemV iv where iv.id.itemId = :itemId  and iv.id.itemTypeId = :itemTypeId ");
        List<ItemView> result = (List<ItemView>)getEntityManager()
            .createQuery(hql)
            .setParameter("itemId", itemId)
            .setParameter("itemTypeId", itemType.getId())
            .setMaxResults(1)
            .getResultList();
        return result.isEmpty()
            ? null : result.get(0);
    }

This dao method always returns empty results, never finding existing rows in the view??? I know those rows exist because when I do getAll() on the same dao I see results and I see a matching row for the criteria.

Is there anything special about selecting rows from a view in H2 database?
Thanks

  • 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-24T06:59:03+00:00Added an answer on May 24, 2026 at 6:59 am

    Ok fixed, I had to use a smaller number for LOCK_TIMEOUT value, so now I can connect to database and see values. Selecting from view problem also fixed.

    I have to say H2 is really neat and elegant. I’m glad, I switched the unit test db to H2.

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

Sidebar

Related Questions

I recently participated a project that replaced a mainframe system with a web (asp.net
Recently Jeff has posted regarding his trouble with database deadlocks related to reading. Multiversion
So I've been working recently on a script to obfuscate client-side code for protecting
I recently spent a great deal of time pulling out a stored procedure back-end
I have been working on quite a complex accordion/form recently and have a select
In a project, I recently replaced a simple form-based file upload with SWFUpload. When
Recently I’ve found myself in a database tangle where management wants the ability to
I'm pretty new to web design and have recently been working on an amatuer
I just recently installed Pyflakes Vim plugin. It works very fine and is very
Recently, we added a feature to our installer that required a couple of the

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.