Using Hibernate 3
I have a problem validating a mapping file that contains <join> and <set> elements.
Java classes:
Code:
public class Agent
{
private Long id;
private lastName;
private firstName;
private String agentNumber;
private Date startDate;
private Date endDate;
private Set<RetailProperty> retailProperties
// getters and setters for each property
}
public class RetailProperty
{
private Long agentId;
private String propertyCode;
private double propertyValue;
// getters and setters for each property
}
DB Tables (Postgresql 8.2):
Code:
tbl_agents
agentid (serial) - pk
lastname (varchar 20)
firstname (varchar 20)
agentnumber (varchar 20)
tbl_agenthistories
agentid (int) - fk to tbl_agents.agentid
startdate (date)
enddate(date)
tbl_retailproperties
agentid (int) - fk to tbl_agents.agentid
propertycode (varchar 50)
value (numeric)
* tbl_agents and tbl_agenthistories are 1-to-1
* tbl_agents and tbl_retailproperties are 1-to-n
* I have no control over the db schema (ie. I cannot change it)
Agent.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name = "Agent" table = "tbl_agents">
<id name = "id" type = "long" column = "agentid">
<generator class = "sequence">
<param name = "sequence">tbl_agent_agentid_seq</param>
</generator>
</id>
<property name = "lastName" type = "string" column = "lastname"/>
<property name = "firstName" type = "string" column = "firstname"/>
<property name = "agentNumber" type = "string" column = "agentnumber"/>
<join table = "tbl_agenthistories" fetch = "join">
<key column = "agentid"/>
<property name = "startDate" type = "date" column = "startdate"/>
<property name = "endDate" type = "date" column = "enddate"/>
</join>
<set name = "retailProperties" table = "tbl_retailproperties">
<key column = "agentid"/>
<one-to-many class = "RetailProperty"/>
</set>
</class>
</hibernate-mapping>
RetailProperty.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name = "RetailProperty" table = "tbl_retailproperties">
<id name = "agentId" type = "long" column = "agentid">
<generator class = "assigned"/>
</id>
<property name = "propertyCode" type = "string" column = "propertycode"/>
<property name = "propertyValue" type = "double" column = "value"/>
</class>
</hibernate-mapping>
RetailProperty.hbm.xml validates. But when I try to validate Agent.hbm.xml I get this:
Code:
Referenced entity at "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd".
The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,
(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,
(property|many-to-one|one-to-one|component|dynamic-component|
properties|any|map|set|list|bag|idbag|array|primitive-array)*,
((join*,subclass*)|joined-subclass*|union-subclass*),loader?,
sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
Which usually means to me that something is wrong with the mapping file. Is there anything in my mapping files that I'm missing?
Note that when I comment out either the <set> or <join> element in Agent.hbm.xml it validates.