openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fay Wang <fyw...@yahoo.com>
Subject Re: Help - Single table inheritance not working with one-to-many collection
Date Tue, 09 Dec 2008 00:11:26 GMT
Hi Mike, 

I am not sure why your table has different values from mine. I don't explicitly set the null
value for TestChild2 in the table. I used the following statements to persist the TestChild1,
TestChild2 and ContainingObject according to your test scenario:

	TestChild1 c1 = new TestChild1();
	c1.setIdColumn(1);
	c1.setColumnA("c1");
	c1.setColumnB("c1");
	c1.setSiteId(1);
		
        TestChild1 c2 = new TestChild1();
        c2.setIdColumn(2);
        c2.setColumnA("c2");
        c2.setColumnB("c2");
        c2.setSiteId(2);
		
        TestChild1 c3 = new TestChild1();
        c3.setIdColumn(3);
        c3.setColumnA("c3");
        c3.setColumnB("c3");
        c3.setSiteId(3);

        TestChild2 c4 = new TestChild2();
        c4.setIdColumn(4);
        c4.setColumnA("c4");
        c4.setSiteId(5);
        
        TestChild2 c5 = new TestChild2();
        c5.setIdColumn(5);
        c5.setColumnA("c5");
        c5.setSiteId(5);
        
        ContainingObject co = new ContainingObject();
        co.addTestChild(c1);
        co.addTestChild(c2);
        co.addTestChild(c3);
        co.setId(1);
        c1.setContainingObject(co);
        c2.setContainingObject(co);
        c3.setContainingObject(co);
         
	tran.begin();
	em.persist(c1);
	em.persist(c2);
        em.persist(c3);
        em.persist(c4);
        em.persist(c5);
        em.persist(co);
	tran.commit();
        em.close();


These operations produce the rows in the test_table as I showed in the earlier mail. Also,
in your ContainingObject, you have: 

    // This is supposed to map a collection of TestChild1 objects.
    @OneToMany (mappedBy="co")
    private Set<TestChild1> testChildren = new HashSet<TestChild1>();

so you should only see NULL value for your containing_obj_id column in your test_table for
rows with discrimator = 'D'. 

    Please let us know how you populate your test_table. Thanks!

Regards,
Fay




--- On Mon, 12/8/08, nibbler <Michael.Schneir@VerizonWireless.com> wrote:

> From: nibbler <Michael.Schneir@VerizonWireless.com>
> Subject: Re: Help - Single table inheritance not working with one-to-many collection
> To: users@openjpa.apache.org
> Date: Monday, December 8, 2008, 3:53 PM
> I think you're actually having the same results as me,
> but your table values
> are different (specifically the containing_obj_id column). 
> My trace looks
> like yours, i.e. it doesn't have the discriminator
> column in the sql.
> 
> 1271  test  TRACE  [main] openjpa.jdbc.SQL - <t 3916302,
> conn 24124380>
> executing prepstmnt 14008569 SELECT t0.id_column,
> t0.discriminator,
> t0.containing_obj_id, t0.column_a, t0.column_b FROM
> test_table t0 WHERE
> t0.containing_obj_id = ? [params=(long) 1]
> 
> Your containing_obj_id column has null values for type
> 'D' discriminators, I
> think that's why you're getting the 3 TestChild1s
> back.  If I null the 'D'
> rows, I also get 3. This Query:
> 
> Query a = em.createQuery("select tc1 from TestChild
> tc1 where
> tc1.containingObjId=1");
> List<TestChild1> list =
> (List<TestChild1>)query.getResultList();
> 
> will result in the correct sql:
> 1444  test  TRACE  [main] openjpa.jdbc.SQL - <t 3916302,
> conn 33187868>
> executing prepstmnt 22975191 SELECT t0.id_column,
> t0.discriminator,
> t0.containing_obj_id, t0.column_a, t0.column_b FROM
> test_table t0 WHERE
> (t0.containing_obj_id = ?) AND t0.discriminator = ?
> [params=(long) 1,
> (String) S]
> 
> The discriminator column is being used here.  I think if
> you set the
> containing_obj_id column for the other rows, you'll see
> the problem I am
> seeing.  Is this a bug in openjpa or am I misusing it?
> 
> I am using openjpa-1.0.2.jar, with the Enhancer.
> 
> Thanks again,
> -Mike
> 
> 
> 
> Fay Wang wrote:
> > 
> > Hi Mike,
> >    I do have the discriminator column. I have the
> following columns in my
> > test_table:
> > 
> > Column name
> > ------------------
> > ID_COLUMN
> > COLUMN_A
> > SITE_ID
> > DISCRIMINATOR
> > COLUMN_B
> > CONTAINING_OBJ_ID
> > 
> > The sql "select id_column, CONTAINING_OBJ_ID,
> discriminator from
> > test_table" generates the following result:
> > 
> > ID_COLUMN            CONTAINING_OBJ_ID DISCRIMINATOR
> > -------------------- -----------------
> -------------------------------
> >                    1                 1 S
> >                    3                 1 S
> >                    4                 - D
> >                    2                 1 S
> >                    5                 - D
> > 
> > To get the trace, you can put 
> > 	<property name="openjpa.Log"
> value="DefaultLevel=TRACE" />
> > in your persistence.xml. 
> > 
> > Regards,
> > Fay
> > 
> >       
> > 
> > 
> 
> -- 
> View this message in context:
> http://n2.nabble.com/Help---Single-table-inheritance-not-working-with-one-to-many-collection-tp1620948p1631574.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


      

Mime
View raw message