[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2920) Polymorphic association with explicit table_per_class strategy: properties of subclass are not retrieved by queries.

Steven Bell (JIRA) noreply at atlassian.com
Tue Sep 9 15:13:04 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2920?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31121#action_31121 ] 

Steven Bell commented on HHH-2920:
----------------------------------

I'm fairly certain this is the same problem I'm seeing.  It's arguably a problem with hsqldb or the hsqldb dialect.  I've logged a bug against hsqldb (ID 2102123), and I've been told this is a known issue with a workaround.  The problem is in polymorphic queries.  You'll get sql in the form:

select t1column1, t1.column2, ... from (
    select column1, column2, ...
    union select column1, null as column2...
) t1

The inner union select works just fine.  When it is put into the temporary table you lose any value that is not common to all tables.  The workaround from the hsqldb folks is to change all the 

null as <column>

statements into

cast(null as <datatype>) as <column>

I suspect this to be a huge problem.  There is a bit of a workaround for hibernate.  If you call <entityManager>.refresh() on the object after you retreive it all the fields will be properly filled in.



> Polymorphic association with explicit table_per_class strategy: properties of subclass are not retrieved by queries.
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-2920
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2920
>             Project: Hibernate3
>          Issue Type: Bug
>    Affects Versions: 3.2.5
>         Environment: Java 1.5 - Hypersonic DB - Standalone application 
>            Reporter: Andrea Silva
>            Priority: Minor
>         Attachments: AuctionIntegrationTest.java, src.zip
>
>
> Item class has a one-to-many association to Bid. Bid class has a subclass called CashBid (meaningless design I know, but that's not the point). If I create and save an instance of Item with an associated CashBid, when I query for items the properties defined in CashBid are not retrieved. 
> NB Bid is not mapped as abstract.
> Here is a code snippet:
> ...
> // First Session
> 		Session session = sessionFactory.openSession();
> 		Transaction transaction = session.beginTransaction();
> 		
> 		Bid bid = new CashBid(new BigDecimal(100.0d), "euro");
> 		Item item = new Item("pc");
> 		
> 		Serializable bidId = session.save(bid);
> 		item.addBid(bid);
> 		session.save(item);
> 		
> 		transaction.commit();
> 		session.close();
> 		
> 		// Second Session
> 		session = sessionFactory.openSession();
> 		transaction = session.beginTransaction();
> 		
> 		//session.load(CashBid.class, bidId);
> 		
> 		Query query = session.createQuery("from Item");
> 		List<Item> list = query.list();
> 		for (Item item_ : list) {
> 			System.out.println(item_);
> 		}
> 		
> 		transaction.commit();
> 		session.close();
> ...
> The bid in the item retrieved by the query is a CashBid (that's correct) but the properties that are defined in CashBid and not in Bid are null. If I uncomment the line 
> //session.load(CashBid.class, bidId);
> the problem is not there anymore.
> If Bid is not mapped as abstract the problem doesn't show.
> My apologies if I'm just missing something very obvious.
> Please find the source code and the mappings attached.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list