[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3345) "select new" + "join fetch" = "owner of the fetched association was not present in the select list"

Andreas Bergander (JIRA) noreply at atlassian.com
Mon Dec 15 08:56:39 EST 2008


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

Andreas Bergander commented on HHH-3345:
----------------------------------------

I added the following code to JoinFetchTest.java in the test suite in 3.3.1.GA:

	public void testJoinFetchTypeSafeJavaObject() {
		Session s = openSession();
		Transaction t = s.beginTransaction();

		ItemWrapper iw = (ItemWrapper) s.createQuery("select new org.hibernate.test.joinfetch.JoinFetchTest$ItemWrapper(i) from Item i left join fetch i.bids left join fetch i.comments").uniqueResult();
		assertTrue( Hibernate.isInitialized( iw.item.getBids() ) );
		assertTrue( Hibernate.isInitialized( iw.item.getComments() ) );
		t.commit();
		s.close();

	}

	private static class ItemWrapper {

		private Item item;

		public ItemWrapper(Item item) {
			this.item = item;
		}
	}


This will produce the follwing error:

-------------------------------------------------------------------------------
Test set: org.hibernate.test.joinfetch.JoinFetchTest
-------------------------------------------------------------------------------
Tests run: 5, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.093 sec <<< FAILURE!
testJoinFetchTypesafeJavaObject(org.hibernate.test.joinfetch.JoinFetchTest)  Time elapsed: 0.015 sec  <<< ERROR!
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=org.hibernate.test.joinfetch.Item.bids,tableName=AuctionBids,tableAlias=bids1_,origin=AuctionItems item0_,colums={item0_.id ,className=org.hibernate.test.joinfetch.Bid}}] [select new org.hibernate.test.joinfetch.JoinFetchTest$ItemWrapper(i) from org.hibernate.test.joinfetch.Item i left join fetch i.bids left join fetch i.comments]


I haven't investigated how difficult this would be to fix, but I'm guessing it's a validation problem.

> "select new" + "join fetch" = "owner of the fetched association was not present in the select list"
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HHH-3345
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3345
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.2.4.sp1
>            Reporter: Anthony Ogier
>
> I want to create a List<B>, each B containing an entity with "A" type, and I also want for each A to force fetching of its "C" property.
> public class B {
>   private A a;
>   public B(A a) {
>     this.a = a;
>   }
> }
> @Entity
> public class A {
>   @ManyToOne @JoinColumn
>   private C c;
> // +get/setter ...
> }
> @Entity
> public class C {
>   @Column
>   private String d;
> // +get/setter ...
> // + at OneToMany
> }
> Here is the HQL :
> select new B(a) from A a left join fetch a.c
> I have that message :
> org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list
> When invoking only "from A a left join fetch a.c", all is good and I have ma List<A> with its "C" properties fetched.
> I think there is a little bug here ... or did I forget something ?

-- 
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