Hi all,
I've got a problem with two entites I try map a OneToMany realtion to. I've
got this to work for other OneToMany realations, but somehow I can't get
this to work.
The scenario is as follows, I have a Dataset entity the can contain many
Resource entities
In DataSet.java the mapping looks like this
/** A set of the resources related to this dataset. */
@OneToMany(mappedBy = "dataSet")
private Set<Resource> resources = new HashSet<Resource>();
In Resource.java it looks like this
@ManyToOne(targetEntity = DataSet.class)
@JoinColumn(name = "dataset_id", referencedColumnName = "id", nullable =
true, updatable = true)
private DataSet dataSet = null;
I've got a unit test, with xml datafiles as the mock information like these
DataSet.db.xml
<?xml version="1.0"?>
<dataset>
<data_set id="1" name="data_set_one" description="my first dataset"
owner_id="user" data_set_id="23456" />
<data_set id="2" name="data_set_two" description="my second dataset"
owner_id="user" data_set_id="2345" />
<data_set id="3" name="data_set_three" description="my third dataset"
owner_id="user" data_set_id="234" />
</dataset>
Resource.db.xml
<?xml version="1.0"?>
<dataset>
<resource id="1" name="resource_one" description="my first resource"
owner_id="user" externalref="23456" type="http"
local_resource="true" localuri="local1"
externaluri="external1"/>
<resource id="5" name="resource_four" description="my fourth resource"
dataset_id="1" owner_id="user_2"
externalref="123456" type="url" local_resource="false"
localuri="local5" externaluri="external5" />
</dataset>
So if the mapping above would have worked dataset with id =1 should have
one resource connected to it. But the unit test below fails
public void testGetDataset() {
dataSetDao.setEntityManager(getEntityManagerFactory()
.createEntityManager());
dataSetDao.setPersistentClass(DataSet.class);
DataSet foundDataSet = dataSetDao.find(1);
assertNotNull(foundDataSet);
assertEquals(1, foundDataSet.getResources().size());
}
Does anyone know what might be wrong here? I use openjpa 1.2.0
Cheers Håkon