-->
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.  [ 3 posts ] 
Author Message
 Post subject: [MAPPING] many-to-many, aucuns insert
PostPosted: Tue Mar 09, 2010 8:41 am 
Beginner
Beginner

Joined: Fri May 23, 2008 4:37 am
Posts: 25
Bonjour à toutes et tous,

Je dois associer un utilisateur à des rôles au travers d'un objet qui vas contenir cette relation.

Mes tables (PostgreSQL) :
Code:
CREATE TABLE user (
  uid SERIAL NOT NULL
);
CREATE TABLE role (
  rid SERIAL NOT NULL
);
CREATE TABLE user_role (
  uid INTEGER NOT NULL,
  rid INTEGER NOT NULL,
  -- FOREIGN KEYS ...
);


Mon objet "Affectation" qui me sert à associer un utilisateur à un ou plusieurs rôles.
Code:
public class Affectation {
  private User user;
  private List<Role> roles;

  // get et set..
}


Et le mapping suivant :
Code:
<class name="xx.Affectation" table="user_role">
  <id column="uid" name="id">
    <generator class="foreign">
      <param name="property">user</param>
    </generator>
  </id>

  <one-to-one name="user" constrained="true" />   

  <bag name="roles" table="user_role" lazy="false">
    <key column="uid"/>            
    <many-to-many class="xx.Role" column="rid" unique="false"/>
  </bag>
</class>


Mais les insertions ne fonctionnent pas car la requête générée n'insère que l'id de l'utilisateur et qu'il y à une contrainte "NOT NULL" sur la colonne "user_role"."rid" :
Code:
insert into user_role (uid) values ('2')

J'ai essayé de rajouter "casacade=all" ou "casacade=save-update" ainsi que "inverse=true" mais rien ne change.

Pouvez-vous m'aider ? Merci


Top
 Profile  
 
 Post subject: Re: [MAPPING] many-to-many, aucuns insert
PostPosted: Tue Mar 09, 2010 10:31 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
salut, ce n'est peut-être pas à cause d'une faute de frappe:
casacade=all" ou "casacade=save-update"

et avec cascade=all ?

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: [MAPPING] many-to-many, aucuns insert
PostPosted: Tue Mar 09, 2010 11:01 am 
Beginner
Beginner

Joined: Fri May 23, 2008 4:37 am
Posts: 25
Bonjour,

Merci mais non, la faute de frappe est uniquement dans ce forum. Un telle faute provoque un exception relativement claire dans Hibernate :
Quote:
org.hibernate.InvalidMappingException: Could not parse mapping document from file src.main\xx\affectation.hbm.xml
...
Caused by: org.xml.sax.SAXParseException: Attribute "casacade" must be declared for element type "bag".
...


Et donc, ni cascade="all", ni cascade="save-update" ne provoque une insertion des identifiants de "Role"s.
Code:
insert into user_role(uid) values ('2')


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.