-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem merging many-to-many with additional fields
PostPosted: Wed Sep 19, 2007 8:58 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Hi,

I have an entity "Asset" that contains a list of other entities "Business". This realizes a many-to-many association. The table is named "ASSET_BUSINESSES" and has two additional columns "ACTIVATED" and "DATE". Persisting a new Asset with existing Businesses results in an Exception due to a NULL value for ACTIVATED (and DATE I assume).

What can I do to tell Hibernate to populate the ACTIVATED and DATE field before persisting into the many-to-many-table?

Here is my Asset entity

Code:
............

   @ManyToMany(targetEntity = Business.class)
   @JoinTable(name = "ASSET_BUSINESSES", joinColumns = { @JoinColumn(name = "ASSETID") }, inverseJoinColumns = { @JoinColumn(name = "BUSINESSID") })
   @Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE,
         org.hibernate.annotations.CascadeType.MERGE,
         org.hibernate.annotations.CascadeType.PERSIST })   
   private List<Business> businesses;

.............


The Exception:

Quote:
java.sql.BatchUpdateException: ORA-01400: Einfügen von NULL in ("ASSETREGISTER_DBA"."ASSET_BUSINESSES"."ACTIVATED") nicht möglich


(meaning NULL is not a valid value for the field "activated" in the join table "asset_businesses").


I think the problem is that my many-to-many table not only contains an "asset" column and a "business" column, but additionally another "activated" column. Hibernate does not seem to populate this field with a value before trying to persist.

What can I do?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 21, 2007 4:06 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
What can I do? I am currently setting default values in the database for activated and date. It works.

Without doing so, would I have to persist each "Asset_Business" after inserting an Asset as second step?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 21, 2007 4:26 am 
Newbie

Joined: Fri Sep 21, 2007 3:32 am
Posts: 6
Hi
I had similar issues a couples of years ago (with hibernate 2.x) and had to manage many2many relationship as a many2one then one to many relationship (in fact I had to manage the relationship table manually).
In addition, in order not to be bothered by insertion order, we generated the fk cosntraint using the "INITIALLY DEFERRED DEFERRABLE" option of oracle

Code:
ALTER TABLE ${model.tableName}
ADD CONSTRAINT ${model.constraintName}
FROM
    FOREIGN KEY (${model.FK})
    REFERENCES ${model.referenceTableName}
    INITIALLY DEFERRED DEFERRABLE
;


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 4:35 pm 
Newbie

Joined: Thu Feb 15, 2007 3:32 pm
Posts: 10
I have a similar problem. Has anyone found a decent solution for this ?

cheers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.