Lisa Stuart wrote:

> Hi,
> 
> I am using JBoss 2.2.1 with CMP beans using hypersonic as the backend
> (default config).
> For three weeks, we have been running the same application that creates
> 9 products (once, after wiping the database and restarting jboss). The
> primary key is Product.name (String). Yesterday, ProductHome.findAll()
> started returning 14 products, some having duplicate primary keys.

Very strange indeed!


> 
> This raised three questions.
> 1. Is there any known issue that would "create" entity beans WITHOUT
> their home.create() being called (the duplicate products appear some
> time after they are created).

No known issue, and I haven't seen this happen to anyone else.


> 2. How can findAll() return duplicate primary keys?  Shouldn't
> hypersonic disallow this, or is this a jboss/jaws bug.

This is a JAWS 'feature' - it doens't actually create a primary key 
constraint when it creates tables for CMP beans (by default). Either 
modify standardjaws.xml or create a jaws.xml for your beans setting 
has-pk-constraint to true for default-entity. Then you'll get the 
behavior that most people want. IIRC, this was made non-default because 
some databases choked on the syntax.


> 3. Is there any way to stop this behaviour, it seems pretty serious.

Have you checked the database by hand to see if there are 9 or 14 rows? 
That'd be the place to start. This is on findAll, correct? That just 
does 'select <field list here> from tablename', so there shouldn't be 
any strange SQL things going on where a 'distinct' would help (i.e. 
those extra rows are probably really in the table!) Having the PK 
constraint there should show us where and when it happens (by blowing up 
at the original point of failure.)

-danch


> 
> I have tested the duplicate primary keys to see if they are references
> to the same objects (==), and they are not.
> 
> What the hell is going on? Any help would be greatly appreciated.
> 
> Thanks,
> Lisa
> ------------------
> 
> [lisa@furby Tests]$ java TestProd
> List of Primary Keys returned by ProductHome.findAll()
> 0:Basil
> 1:Alfalfa
> 2:Delivery
> 3:Delivery
> 4:Corriander
> 5:Licyourass
> 6:Licyourass
> 7:Tomatoes
> 8:Tomatoes
> 9:Mushies
> 10:Happles
> 11:Happles
> 12:Horanges
> 13:Horanges
> ----------------------- TestProd.java ---------------
> import java.util.Collection;
> import java.util.Iterator;
> 
> 
> public class TestProd {
> 
>     public static void main (String[] args) throws Exception {
> 
>         ProductHome ph = (ProductHome)Util.getHome("Product",
> ProductHome.class);
>         Collection prods = ph.findAll();
>         Iterator i = prods.iterator();
>         int cnt = 0;
>         System.out.println("List of Primary Keys returned by
> ProductHome.findAll()");
>         Product lp = null;
>         while (i.hasNext()){
>             Product p = (Product)i.next();
>             if ( p == lp ) System.out.println("NEXT PRODUCT is SAME
> OBJECT AS LAST");
>             System.out.println(cnt + ":" + p.getPrimaryKey());
>             cnt++;
>             lp = p;
>         }
>     }
> }
> ----------------- snippet of ejb-jar.xml ----------------
>  <entity>
>       <ejb-name>Product</ejb-name>
>       <home>ProductHome</home>
>       <remote>Product</remote>
>       <ejb-class>ProductBean</ejb-class>
>       <persistence-type>Container</persistence-type>
>       <prim-key-class>java.lang.String</prim-key-class>
>       <reentrant>False</reentrant>
>       <cmp-field><field-name>name</field-name></cmp-field>
>       <cmp-field><field-name>desc</field-name></cmp-field>
>       <cmp-field><field-name>unit</field-name></cmp-field>
>       <cmp-field><field-name>unitCostPrice</field-name></cmp-field>
>       <cmp-field><field-name>qtyOnHand</field-name></cmp-field>
>       <cmp-field><field-name>minQty</field-name></cmp-field>
>       <cmp-field><field-name>catPK</field-name></cmp-field>
>       <primkey-field>name</primkey-field>
>       <ejb-ref>
>         <ejb-ref-name>ejb/Category</ejb-ref-name>
>         <ejb-ref-type>Entity</ejb-ref-type>
>         <home>CategoryHome</home>
>         <remote>Category</remote>
>         <ejb-link>Category</ejb-link>
>       </ejb-ref>
>     </entity>
> 
> 
> 
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user



_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to