J
jstorta
I have 2 related tables with a many-to-one mapping setup. It all
works great when retrieving information, but I cannot figure out a way
to perform an update to the table with the foreign key.
I am simplifying what I have for the purposes this discussion. There
is more configuration with regards to DAOs and Beans and Spring
config, but I do not know that it pertains to this so I will leave it
out unless I need to include it.
Here are the basics of my configuration.
*******Database tables
contact
contact_id
project
project_id
contact_id
*******Corresponding classes
public class Contact {
private String contactId;
//getters, setters, constructors etc
}
public class Project {
private String projectId;
private Contact projectOwner;
//getters, setters, constructors etc
}
*******hbm mappings
<hibernate-mapping>
<class name="mypkg.Contact" table="contact">
<id column="contact_id" name="contactId"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="mypkg.Project" table="project">
<id column="project_id" name="projectId">
<generator class="increment"/>
</id>
<many-to-one name="projectOwner" class="mypkg.Contact"
column="contact_id" lazy="false"/>
</class>
</hibernate-mapping>
I am using JSF to display the contents of the project table. It works
great. hibernate pulls all of the values and populates the Contact
object within each Project object. My problem is, how do I update the
contact_id foreign key on the project table?
I do not want to touch the Contact object or table. I just want to
update the contact_id field in the project table so that the project
references a different contact.
I am sure I can come up with some way to do this, but it seems like
something that should be pretty common and I would like to avoid
needless coding.
Thanks,
John
works great when retrieving information, but I cannot figure out a way
to perform an update to the table with the foreign key.
I am simplifying what I have for the purposes this discussion. There
is more configuration with regards to DAOs and Beans and Spring
config, but I do not know that it pertains to this so I will leave it
out unless I need to include it.
Here are the basics of my configuration.
*******Database tables
contact
contact_id
project
project_id
contact_id
*******Corresponding classes
public class Contact {
private String contactId;
//getters, setters, constructors etc
}
public class Project {
private String projectId;
private Contact projectOwner;
//getters, setters, constructors etc
}
*******hbm mappings
<hibernate-mapping>
<class name="mypkg.Contact" table="contact">
<id column="contact_id" name="contactId"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="mypkg.Project" table="project">
<id column="project_id" name="projectId">
<generator class="increment"/>
</id>
<many-to-one name="projectOwner" class="mypkg.Contact"
column="contact_id" lazy="false"/>
</class>
</hibernate-mapping>
I am using JSF to display the contents of the project table. It works
great. hibernate pulls all of the values and populates the Contact
object within each Project object. My problem is, how do I update the
contact_id foreign key on the project table?
I do not want to touch the Contact object or table. I just want to
update the contact_id field in the project table so that the project
references a different contact.
I am sure I can come up with some way to do this, but it seems like
something that should be pretty common and I would like to avoid
needless coding.
Thanks,
John