I am having problems setting relationships between entities. I created a
simple example with two tables (Person, Address). Person has a relationship
to Address. When I call setAddress() I get the following exception:
[DEBUG DomainHelper] start configuration loading.
[DEBUG DomainHelper] loaded domain: CayenneTstDomain
[DEBUG DomainHelper] loading <map name='Map' location='Map'>.
[DEBUG DomainHelper] loaded <map name='Map' location='Map'>.
[DEBUG DomainHelper] loading <node name='Node' datasource='Node'
factory='org.objectstyle.cayenne.conf.DriverDataSourceFactory'>.
[DEBUG DomainHelper] node DbAdapter:
org.objectstyle.cayenne.dba.mysql.MySQLAdapter
[DEBUG DomainHelper] using factory:
org.objectstyle.cayenne.conf.DriverDataSourceFactory
[DEBUG DriverDataSourceFactory] loading driver information from (Node).
[DEBUG DriverDataSourceFactory] location found in filesystem.
[DEBUG DriverDataSourceFactory] loading driver org.gjt.mm.mysql.Driver
[DEBUG DriverDataSourceFactory] loading user name and password.
[DEBUG QueryLogger] Connecting. DataSource information:
Driver class: org.gjt.mm.mysql.Driver
Min. Pool Size: 1
Max. Pool Size: 1
Database URL: jdbc:mysql://localhost/Cayenne
Login: root
Password: ******* [DEBUG QueryLogger] +++ Connecting: SUCCESS.
[DEBUG DomainHelper] loaded datasource.
[DEBUG DomainHelper] loaded map-ref: Map.
[INFO QueryLogger] --- will run 2 queries.
[INFO QueryLogger] SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME =
'ADDRESS' - prepared in 0 ms.
[INFO QueryLogger] === returned 1 row. - took 60 ms. [DEBUG
DefaultOperationObserver] result count: 1
[INFO QueryLogger] UPDATE AUTO_PK_SUPPORT SET NEXT_ID = NEXT_ID + 20 WHERE
TABLE_NAME = 'ADDRESS' - prepared in 0 ms.
[INFO QueryLogger] === updated 1 row. [DEBUG DefaultOperationObserver]
update count: 1
[INFO QueryLogger] +++ transaction committed. [DEBUG
DefaultOperationObserver] transaction committed
[INFO QueryLogger] --- will run 1 query.
[INFO QueryLogger] INSERT INTO ADDRESS (ADDRESS_ID, STREET_ADDRESS_2, CITY,
STREET_ADDRESS_1, STATE, ZIP) VALUES (?, ?, ?, ?, ?, ?) [params: 200, NULL,
'Austin', '2000 Research Blvd', 'TX', '78759'] - prepared in 0 ms.
[INFO QueryLogger] === updated 1 row. [DEBUG DefaultOperationObserver]
update count: 1
[INFO QueryLogger] +++ transaction committed. [DEBUG
DefaultOperationObserver] transaction committed
java.lang.NullPointerException
at
org.objectstyle.cayenne.CayenneDataObject.setReverseRelationship(CayenneData
Object.java:249)
at
org.objectstyle.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.j
ava:234)
at _Person.setAddress(_Person.java:37)
at CayenneTst.test1(CayenneTst.java:38)
at CayenneTst.<init>(CayenneTst.java:15)
at CayenneTst.main(CayenneTst.java:45)
Exception in thread "main" Process Exit...
Here is the test code:
import java.io.File;
import java.util.List;
import org.objectstyle.cayenne.access.*;
import org.objectstyle.cayenne.exp.*;
import org.objectstyle.cayenne.query.*;
import org.objectstyle.cayenne.conf.Configuration;
public class CayenneTst extends Object
{
public DataContext ctxt;
public CayenneTst()
{
initialize();
test1();
}
public void initialize()
{
Configuration conf = Configuration.getSharedConfig();
ctxt = conf.getDomain().createDataContext();
}
public void test1()
{
Address address = new Address();
address.setCity("Austin");
address.setState("TX");
address.setStreetAddress1("2000 Research Blvd");
address.setZip("78759");
ctxt.registerNewObject(address, "Address");
ctxt.commitChanges();
Person person = new Person();
person.setFirstName("John");
person.setMiddleInitial("H");
person.setLastName("Cayenne");
person.setAddress(address);
ctxt.registerNewObject(address, "Address");
ctxt.commitChanges();
}
public static void main(String[] args)
{
new CayenneTst();
}
}
Here is the Map:
<?xml version="1.0" encoding="UTF-8"?>
<data-map>
<db-entity name="ADDRESS">
<db-attribute name="ADDRESS_ID" type="INTEGER"
isPrimaryKey="true" isMandatory="true"/>
<db-attribute name="CITY" type="VARCHAR" length="20"/>
<db-attribute name="STATE" type="VARCHAR" length="2"/>
<db-attribute name="STREET_ADDRESS_1" type="VARCHAR"
length="20"/>
<db-attribute name="STREET_ADDRESS_2" type="VARCHAR"
length="20"/>
<db-attribute name="ZIP" type="VARCHAR" length="15"/>
</db-entity>
<db-entity name="PERSON">
<db-attribute name="ADDRESS_ID" type="INTEGER"/>
<db-attribute name="FIRST_NAME" type="VARCHAR" length="20"/>
<db-attribute name="LAST_NAME" type="VARCHAR" length="20"/>
<db-attribute name="MIDDLE_INITIAL" type="VARCHAR"
length="1"/>
<db-attribute name="PERSON_ID" type="INTEGER"
isPrimaryKey="true" isMandatory="true"/>
</db-entity>
<obj-entity name="Address" className="Address"
dbEntityName="ADDRESS">
<obj-attribute name="city" type="java.lang.String"
db-attribute-name="CITY"/>
<obj-attribute name="state" type="java.lang.String"
db-attribute-name="STATE"/>
<obj-attribute name="streetAddress1" type="java.lang.String"
db-attribute-name="STREET_ADDRESS_1"/>
<obj-attribute name="streetAddress2" type="java.lang.String"
db-attribute-name="STREET_ADDRESS_2"/>
<obj-attribute name="zip" type="java.lang.String"
db-attribute-name="ZIP"/>
</obj-entity>
<obj-entity name="Person" className="Person" dbEntityName="PERSON">
<obj-attribute name="firstName" type="java.lang.String"
db-attribute-name="FIRST_NAME"/>
<obj-attribute name="lastName" type="java.lang.String"
db-attribute-name="LAST_NAME"/>
<obj-attribute name="middleInitial" type="java.lang.String"
db-attribute-name="MIDDLE_INITIAL"/>
</obj-entity>
<db-relationship name="address" source="PERSON" target="ADDRESS"
toDependentPK="true" toMany="false">
<db-attribute-pair source="ADDRESS_ID" target="ADDRESS_ID"/>
</db-relationship>
<obj-relationship name="address" source="Person" target="Address"
toMany="false">
<db-relationship-ref source="PERSON" target="ADDRESS"
name="address"/>
</obj-relationship>
</data-map>
I am running on the Cayenne build from 8-13. Is this a bug or am I doing
something real stupid in CA.
J.R.
This archive was generated by hypermail 2.0.0 : Mon Aug 19 2002 - 01:40:20 EDT