[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - NULL FOREIGN KEY

pvelarde do-not-reply at jboss.com
Tue Oct 9 08:17:02 EDT 2007


Hi all,

I've got a master-detail relation mapped with these two simple EJB3.0 beans below; when I modify master record, the detail records lose the join with master so masterid is set to null in detail table.

I don't want any cascade efect so CASCADETYPE is not established in master.

I've read something about this problem in forus but have no solution. Is this an Hibernate bug¿? have any idea ¿?

thanks for your help.

MASTER BEAN CODE

@Entity
  | @Table(name = "master")
  | @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
  | public class MasterEJB implements Serializable {
  | 
  | ...
  | 
  | protected Collection<DetailEJB> details = new Vector<DetailEJB>();
  | 
  | @OneToMany(targetEntity = DetailEJB.class)
  | @JoinColumn(name="master_id")
  | public Collection<DetailEJB> getDetails() {
  |    return details;
  | }
  | 
  | public void setDetails(Collection<DetailEJB> details) {
  |    this.details = details;
  | }
  | 
  | ...
  | 

DETAIL BEAN CODE

@Entity
  | @Table(name = "detail")
  | @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
  | public class DetailEJB implements Serializable {
  | 
  | ...
  | 
  | @ManyToOne(optional=false)
  | @JoinColumn(name="master_id", nullable=false)
  | public Integer getMasterID() {
  |    return masterid;
  | }
  | 
  | public void setMasterID(Integer masterid) {
  |    this.masterid = masterid;
  | }
  | 
  | ...
  | 

Each bean has its own table on a MySQL DBMS, here are master and detail tables definitions:

CREATE TABLE `master` (
  |   `id` int(11) NOT NULL auto_increment,
  |   PRIMARY KEY  (`id`)
  | ) ENGINE=InnoDB
  | 
  | CREATE TABLE `detail` (
  |   `id` int(11) NOT NULL auto_increment,
  |   `master_id` int(11) default '0',
  |   PRIMARY KEY  (`id`),
  |   KEY `FK30E0AFBF496DF04C` (`master_id`)
  | ) ENGINE=InnoDB
  | 
  | 



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4092982#4092982

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4092982




More information about the jboss-user mailing list