Beginner |
|
Joined: Fri Oct 06, 2006 7:11 am Posts: 32
|
Hi,
I've not put version information etc here as its not relative.
I'm new to Hibernate and having some problems with the concepts.
My problem is as follows.
I have the following concrete classes
CertificateStatementTitle
CertificateStatement
The relationship between classes is as follows:
CertificateStatementTitle has a 0 or more CertificateStatement.
My problem is that I need to have an admin function in my application whereby
I add statements without having to define a StatementTitle.
When I try to do this at the minute I am getting :
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (DPCS.FKA29006CCA379C88B) violated - parent key not found
I think the problem is that my relationship is bi-directional so I can't insert a statement until
I have an existing StatementTitle.
So my question is really, how can I remove this bi-directional relationship and just keep it
that the StatementTitle has 0 or more Statments associated with it and that a Statement can
exist as its own entity.
I've added my code below.
thanks for any help in advance
(I have left out non relevant fields):
public class StatementTitle implements Serializable{
private Long id;
private Set statements = new HashSet();
public StatementTitle() {
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setStatements(Set statements) {
this.statements = statements;
}
public Set getStatements() {
return statements;
}
public void addStatement(Statement statement) {
this.statements.add(statement);
statement.setStatementTitle(this);
}
}
<?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="ie.gov.agriculture.dpcs.cert.StatementTitle" table="DPCS_STATEMENT_TITLE">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<set name="statements" lazy="true" table="DPCS_STATEMEMT">
<key column="id"/>
<one-to-many class="ie.gov.agriculture.dpcs.cert.Statement"/>
</set>
</class>
</hibernate-mapping>
public class Statement implements Serializable{
private Long id;
private StatementTitle statementTitle = null;
public Statement() {
}
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public StatementTitle getStatementTitle() {
return statementTitle;
}
public void setStatementTitle(StatementTitle statementTitle) {
this.statementTitle = statementTitle;
}
}
<?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="ie.gov.agriculture.dpcs.cert.Statement" table="DPCS_STATEMENT">
<id name="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="statementTitle"
class="ie.gov.agriculture.dpcs.cert.StatementTitle"
column="STATEMENT_TITLE"/>
</class>
</hibernate-mapping>
|
|