aspose file tools*
The moose likes Object Relational Mapping and the fly likes Composite Primary Key And Speedo Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Composite Primary Key And Speedo" Watch "Composite Primary Key And Speedo" New topic
Author

Composite Primary Key And Speedo

A Tavouille
Greenhorn

Joined: May 12, 2004
Posts: 3
I m using speedo1.1.1 and i ve 2 problem with composite primary key


1: declaing "object-id-class" in .jdo
I ve a table (Address) with a three field primary-key.
and the .jdo file is :
<class name="Address"
identity-type="application"
objectid-class="invoice.AddressID">
<extension vendor-name="speedo" key="sql-name" value="SE_ADDRESS"/>
<field name="name" primary-key="true">
<extension vendor-name="speedo" key="sql-name" value="NAME"/>
<extension vendor-name="speedo" key="size" value="30"/>
</field>
<field name="street" primary-key="true">
<extension vendor-name="speedo" key="sql-name" value="STREET"/>
<extension vendor-name="speedo" key="size" value="60"/>
</field>
<field name="zip">
<extension vendor-name="speedo" key="sql-name" value="ZIP"/>
<extension vendor-name="speedo" key="size" value="6"/>
</field>
<field name="town" primary-key="true">
<extension vendor-name="speedo" key="sql-name" value="TOWN"/>
<extension vendor-name="speedo" key="size" value="20"/>
</field>
<field name="country">
<extension vendor-name="speedo" key="sql-name" value="COUNTRY"/>
<extension vendor-name="speedo" key="size" value="20"/>
</field>
</class>

The AddressId is the primary key of the Address

public class AddressId implements Serialisable {
//......
private AddressID(){

}
public AddressID(String value) {
StringTokenizer token = new StringTokenizer(value,"//");
token.nextToken();
name=(String)token.nextToken();
town=(String)token.nextToken();;
street=(String)token.nextToken();

}
public String toString(){
return this.getClass().getName()+"//"+name+"//"+town +"//" + street;


}
/**
*Implementation of equals method.
*/
public boolean equals (Object obj)
{
if (obj == this)
return true;

if (!(obj instanceof AddressID))
return false;

AddressID a = (AddressID)obj;

return name.equals(a.name)
&& town.equals(a.town)
&& street.equals(a.street);

}

/**
*Implementation of hashCode method that supports the
*equals-hashCode contract.
*/
public int hashCode (){
return this.name.hashCode() ^ this.town.hashCode()^ this.street.hashCode();
}

//.....//
}

And this is the "client" :
AddressID id = new AddressID();
id.name="Bruno";
id.town="Paris";
id.street="?";
Object oid = pm.newObjectIdInstance(Address.class,id.toString());
When runing client, exception is thrown :
java.lang.NoSuchMethodError: invoice.AddressID.jdoSetPersistentClassName(Ljava/lang/String V
[java] at invoice.AddressIDPName.getNewUserId(AddressIDPName.java)
[java] at org.objectweb.speedo.naming.lib.UserIdCompositeNamingManager.decode(UserIdCompositeNamingManager.java:125)
[java] at org.objectweb.speedo.naming.lib.NamingManagerFactory.decode(NamingManagerFactory.java:130)
[java] at org.objectweb.speedo.mapper.lib.BasicJormFactory.decodeAbstract(BasicJormFactory.java:515)
[java] at org.objectweb.fractal.julia.generated.C39fb1fbd_0.decodeAbstract(INTERFACE[PNameCoder])
[java] at org.objectweb.speedo.pm.lib.SpeedoProxyManager.newObjectIdInstance(SpeedoProxyManager.java:1116)
[java] at org.objectweb.fractal.julia.generated.C934ff4c5_0.newObjectIdInstance(INTERFACE[ProxyManager])
[java] at invoice.InvoiceAppsHelper.printProduct(InvoiceAppsHelper.java:283)
[java] at invoice.Printer.main(Printer.java:28)
[java] Exception in thread "main"
[java] Java Result: 1


So i add the methode jdoSetPersistentClassName to AddressId and when running the client, an another exception is thrown :
[java] javax.jdo.JDOUserException: Impossible to decode the identifier invoice.AddressID//Bruno//Paris//? of the class invoice.Address
[java] NestedThrowables:
[java] org.objectweb.jorm.api.PException: No identity manager able to decode:
[java] pnc=invoice.AddressIDBinder@1576e70
[java] oid=invoice.AddressID//Bruno//Paris//?
[java] clazz=class invoice.Address
[java] at org.objectweb.speedo.mapper.lib.BasicJormFactory.decodeAbstract(BasicJormFactory.java:517)
[java] at org.objectweb.fractal.julia.generated.C39fb1fbd_0.decodeAbstract(INTERFACE[PNameCoder])
[java] at org.objectweb.speedo.pm.lib.SpeedoProxyManager.newObjectIdInstance(SpeedoProxyManager.java:1116)
[java] at org.objectweb.fractal.julia.generated.C934ff4c5_0.newObjectIdInstance(INTERFACE[ProxyManager])
[java] at invoice.InvoiceAppsHelper.printProduct(InvoiceAppsHelper.java:283)
[java] at invoice.Printer.main(Printer.java:28)


What's wrong ???


I ve try a another way to find an Adress object by id, and this code work fine :
AddressID addid3=new AddressID();
addid3.name="Bruno";
addid3.town="Paris";
addid3.street="?";
pm.getObjectById(addid3,false);

it's a good idea to do that ?? (portability....)


2 : without declaring object-id-class
I change the configuration and remove the object-id-class. Speedo generate for me the id class.

In order to test, i execute query, and then, i use getObjectId on each item. Then i use getObjectById(id) . :

query= pm.newQuery(Address.class);

Collection items = (Collection) query.execute();
Iterator ititems = items.iterator();
while(ititems.hasNext()){
Address p =(Address)ititems.next();
Object oid = pm.getObjectId(p);
pm.getObjectById(oid);

}
query.closeAll();

When running this code, excepton is thrown :
[java] javax.jdo.JDOUserException: Impossible to encode the identifier :invoice.Address_IdPName@3e27ed3f / pnc: invoice.Address / name=Albert/ street=Veflert / town=Djakarta
[java] at org.objectweb.speedo.mapper.lib.BasicJormFactory.encodeAbstract(BasicJormFactory.java:600)
[java] at org.objectweb.fractal.julia.generated.C39fb1fbd_0.encodeAbstract(INTERFACE[PNameCoder])
[java] at org.objectweb.speedo.pm.lib.SpeedoProxyManager.getObjectId(SpeedoProxyManager.java:700)
[java] at org.objectweb.fractal.julia.generated.C934ff4c5_0.getObjectId(INTERFACE[ProxyManager])
[java] at invoice.InvoiceAppsHelper.printProduct(InvoiceAppsHelper.java:211)
[java] at invoice.Printer.main(Printer.java:28)

[ September 05, 2004: Message edited by: A Tavouille ]

[ September 05, 2004: Message edited by: A Tavouille ]

[ September 05, 2004: Message edited by: A Tavouille ]

[ September 05, 2004: Message edited by: A Tavouille ]

[ September 06, 2004: Message edited by: A Tavouille ]
[ September 06, 2004: Message edited by: A Tavouille ]
Erik Bengtson
Ranch Hand

Joined: Dec 06, 2003
Posts: 90
using this is fine



but there is not reason to do so as: "oid.toString().equals(id.toString())"

so, the below is much better for your application performance



You should get in touch to the speedo team.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Composite Primary Key And Speedo
 
Similar Threads
Jboss 3.0.4 CMP2 with Oracle 8.1.6
Hibernate, User and Address with association table between
CMP 2.0 problem in Jboss 4.0.2
Use of set tag in Hibernate mapping file?
Using Oracle sequence with JBOSS