openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "axel becker (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (OPENJPA-2431) Native-Query with multiple joins to same table returning wrong result
Date Thu, 26 Sep 2013 08:48:02 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-2431?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13778577#comment-13778577
] 

axel becker edited comment on OPENJPA-2431 at 9/26/13 8:46 AM:
---------------------------------------------------------------

{code:title=Our TestNG to call the Query.|borderStyle=solid}


	/**
	 * Issue:<br/>
	 * If we join two types with different alliasses, we get for both types the same instance.
<br/>
	 * This is wrong. We schould get different instances with different values.<br/>
	 * This test reproduce this issue and should help to simplify the behavior.
	 * 
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Test(enabled = true, groups = TestGroups.JPA, dependsOnMethods = {})
	public void testFindTestEntity() throws Exception {

		final Query query = getEntityManager().createNamedQuery("TestEntityIndexReadonly.findByDueDate");

		final List<Object[]> objList = query.getResultList();

		for (final Object[] objects : objList) {
			Assert.assertEquals(objects[0].getClass(), TestEntityIndexReadonly.class);
			Assert.assertEquals(objects[1].getClass(), TestEntityCurrencyReadonly.class);
			Assert.assertEquals(objects[2].getClass(), TestEntityTenorReadonly.class);
		}
	}
{code} 
                
      was (Author: axel_becker):
    {code:title=Our TestNG to call the Query.|borderStyle=solid}


	/**
	 * Issue:<br/>
	 * If we join two types with different alliasses, we get for both types the same instance.
<br/>
	 * This is wrong. We schould get different instances with different values.<br/>
	 * This test reproduce this issue and should help to simplify the behavior.
	 * 
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Test(enabled = true, groups = TestGroups.JPA, dependsOnMethods = {})
	public void testFindTestEntity() throws Exception {

		final Query query = getEntityManager().createNamedQuery("TestEntityIndexReadonly.findByDueDate");

		final List<Object[]> objList = query.getResultList();
		// Loop over Objectarray an set the Relations :-(
		for (final Object[] objects : objList) {
			Assert.assertEquals(objects[0].getClass(), TestEntityIndexReadonly.class);
			Assert.assertEquals(objects[1].getClass(), TestEntityCurrencyReadonly.class);
			Assert.assertEquals(objects[2].getClass(), TestEntityTenorReadonly.class);
		}
	}
{code} 
                  
> Native-Query with multiple joins to same table returning wrong result
> ---------------------------------------------------------------------
>
>                 Key: OPENJPA-2431
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2431
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc, jpa, kernel, sql
>    Affects Versions: 2.1.0, 2.1.1
>         Environment: Websphere 8 Runtime and ApplicationServer
> Windows XP
> J2EE 6
> Oracle 11
>            Reporter: axel becker
>            Priority: Critical
>         Attachments: resultlist.jpeg, TestEntityCurrencyReadonly.java, testentityimmutable.jpa.xml,
TestEntityIndexReadonly.java, TestEntityTenorReadonly.java, TestEntityTypeReadonly.java, TestReadonlyPrimaryKey.java
>
>
> The resultset of the following native query should has a result of an objectarray with
3 different returnvalues. 
> 1) TestEntityIndexReadonly: the holder entity mapped to table indexes 
> 2) TestEntityCurrencyReadonly: currency mapped to table types 
> 3) TestEntityTenorReadonly: tenor mapped to table types too 
> But i get an Resultset with 3 Objects where the second and the third object are the same
(same instance). 
> 1) TestEntityIndexReadonly: 
> 2) TestEntityCurrencyReadonly: 
> 3) TestEntityCurrencyReadonly: 
> The Query:
> 	<named-native-query name="TestEntityIndexReadonly.findByDueDate"
> 		result-set-mapping="TestEntityIndexReadonly.findByDueDateResult">
> 		<query>
>     <![CDATA[
> 	SELECT id.*, cur.*, tenor.*
> 	  FROM indexes id
> 	  LEFT JOIN types cur ON cur.t_id = id.id_t_cur_id
> 	  LEFT JOIN types tenor ON tenor.t_id = id.id_t_tenor_id
>      ]]>
>     </query>
> 	</named-native-query>
> 	<!--  ResultSets -->
> 	<sql-result-set-mapping name="TestEntityIndexReadonly.findByDueDateResult">
> 		<entity-result entity-class="de.test.openjpa.TestEntityIndexReadonly" />
> 		<entity-result entity-class="de.test.openjpa.TestEntityCurrencyReadonly" />
> 		<entity-result entity-class="de.test.openjpa.TestEntityTenorReadonly" />
> 	</sql-result-set-mapping>
> Hint: For the entity-3 i get the same oid as for entity-2. The reason is, the JDBCStoreManager
(Line 1031) "Object oid = base.getObjectId(this, result, null, true, null);" gets the same
oid for entity-2 and entity-3. 
> I will attache the javaclasses and mapping.xml and a screen from the wrong resultset.

> see also: https://issues.apache.org/jira/browse/openjpa-2218. 
> I tried to find out a workaround by removing the abstract parent from TestEntityCurrencyReadonly
and TestEntityTenorReadonly. 
> In this case, i get the correct Objectinstances but the third entity (TestEntityTenorReadonly)
holds the values from TestEntityCurrencyReadonly (also wrong)! 
> Hope it helps to find the bug.
> Axel

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message