-->
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: Löschen von "one-to-many" Hibernate 3.0.5, JBoss
PostPosted: Wed Jun 08, 2005 2:55 am 
Newbie

Joined: Tue May 31, 2005 10:31 am
Posts: 5
Hallo zusammen!

Ich versuche verzweifelt einen Datensatz zu löschen, teilweise für hibernate das löschen auch aus, zumindest laufen die entsprechenden Funktionen fehlerfrei durch, doch auf der DB passiert nichts.
Wenn ich dann die selben Statements im SQL Worksheef ausführe fuktioniert es!
Das ganze wird von einem Session Bean im Jboss ausgeführt.
Andere Manipulationen der Daten sind erfolgreich, nur löschen kann ich den Eintrag nicht.


Hibernate version:
3.0.5
JBoss version:
4.0.2
Name and version of the database you are using:
Oracle9i 9.2.0.4

Mapping documents:
Mapping für AC_USER

Code:
<hibernate-mapping>
  <class name="de.psb_gmbh.main.business.persistence.AcUser" table="AC_USER" schema="LAGERDBA">
    <id name="UserId">
      <column name="USER_ID"/>
      <generator class="assigned" />
    </id>
    <many-to-one name="AcGroup" class="de.psb_gmbh.main.business.persistence.AcGroup">
      <column name="MASTER_GROUP_ID"/>
    </many-to-one>
    <property name="LoginName">
      <column name="LOGIN_NAME"/>
    </property>
    <property name="Name">
      <column name="NAME"/>
    </property>
    <property name="Password">
      <column name="PASSWORD"/>
    </property>
    <property name="CheckCount">
      <column name="CHECK_COUNT"/>
    </property>
[b]    <set name="SetOfAcUserToGroup">
      <key>
        <column name="USER_ID" />
      </key>
      <one-to-many class="de.psb_gmbh.main.business.persistence.AcUserToGroup" />
    </set>[/b]
  </class>
</hibernate-mapping>



Mapping für AC_USER_TO_GROUP
Code:
<hibernate-mapping>
  <class name="de.psb_gmbh.main.business.persistence.AcUserToGroup" table="AC_USER_TO_GROUP" schema="LAGERDBA">
    <composite-id name="id" class="de.psb_gmbh.main.business.persistence.AcUserToGroupId">
      <key-many-to-one name="AcGroup" class="de.psb_gmbh.main.business.persistence.AcGroup">
        <column name="GROUP_ID"/>
      </key-many-to-one>
     [b] <key-many-to-one name="AcUser" class="de.psb_gmbh.main.business.persistence.AcUser">
        <column name="USER_ID"/>
      </key-many-to-one>[/b]
    </composite-id>
    <property name="CheckCount">
      <column name="CHECK_COUNT"/>
    </property>
  </class>
</hibernate-mapping>



AcUser.java
Code:
public class AcUser implements java.io.Serializable {

  // Fields
  private String UserId;
  private AcGroup AcGroup;
  private String LoginName;
  private String Name;
  private String Password;
  private Integer CheckCount;
  private Set<AcUserToGroup> SetOfAcUserToGroup;

  // Constructors
  public AcUser() {
  }

  // Property accessors
 
  public String getUserId() {
    return this.UserId;
  }

  public void setUserId(String UserId) {
    this.UserId = UserId;
  }

  public AcGroup getAcGroup() {
    return this.AcGroup;
  }

  public void setAcGroup(AcGroup AcGroup) {
    this.AcGroup = AcGroup;
  }

  public String getLoginName() {
    return this.LoginName;
  }

  public void setLoginName(String LoginName) {
    this.LoginName = LoginName;
  }

  public String getName() {
    return this.Name;
  }

  public void setName(String Name) {
    this.Name = Name;
  }

  public String getPassword() {
    return this.Password;
  }

  public void setPassword(String Password) {
    this.Password = Password;
  }

  public Integer getCheckCount() {
    return this.CheckCount;
  }

  public void setCheckCount(Integer CheckCount) {
    this.CheckCount = CheckCount;
  }

  public Set<AcUserToGroup> getSetOfAcUserToGroup() {
    return this.SetOfAcUserToGroup;
  }

  public void setSetOfAcUserToGroup(Set<AcUserToGroup> setOfAcUserToGroup) {
    this.SetOfAcUserToGroup = setOfAcUserToGroup;
  }
}


AcUserToGroup.java
Code:
public class AcUserToGroup  implements java.io.Serializable {

// Fields   
  private de.psb_gmbh.main.business.persistence.AcUserToGroupId id;
  private java.lang.Integer CheckCount;

  // Constructors
  public AcUserToGroup() {
  }
 
  // Property accessors
  public AcUserToGroupId getId () {
      return this.id;
  }
 
  public void setId (AcUserToGroupId id) {
      this.id = id;
  }
 
  public Integer getCheckCount () {
      return this.CheckCount;
  }
 
public void setCheckCount (Integer CheckCount) {
      this.CheckCount = CheckCount;
  }
}




AcUserToGroupId.java
Code:
public class AcUserToGroupId implements java.io.Serializable {

  // Fields
  private AcGroup AcGroup;
  private AcUser AcUser;

  // Constructors
  public AcUserToGroupId() {
  }

  // Property accessors
  public de.psb_gmbh.main.business.persistence.AcGroup getAcGroup() {
    return this.AcGroup;
  }

  public void setAcGroup(
      de.psb_gmbh.main.business.persistence.AcGroup AcGroup) {
    this.AcGroup = AcGroup;
  }

  public de.psb_gmbh.main.business.persistence.AcUser getAcUser() {
    return this.AcUser;
  }

  public void setAcUser(de.psb_gmbh.main.business.persistence.AcUser AcUser) {
    this.AcUser = AcUser;
  }




Code between sessionFactory.openSession() and session.close():
Code:
    /** @ejb.interface-method view-type = "remote" */
    public void deleteAcUser(String userId) throws BusinessException{
      String msg =  "AcUserMgrBean.deleteAcUser("+userId+")";
      try {
        hsession = factory.getCurrentSession();
        hsession.createSQLQuery("DELETE FROM ac_user_to_group WHERE user_id='"+userId+"'");
        hsession.createSQLQuery("DELETE FROM ac_user WHERE user_id='"+userId+"'");
        log(msg);
      } catch (Exception e) {
        throw new BusinessException(msg, e.getCause());
      }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 5:05 am 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
Würde mal auf Transaktionsproblem/Sessionhandling tippen, Stichworte: begin/commitTransaction usw.

HTH
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 2:18 am 
Newbie

Joined: Tue May 31, 2005 10:31 am
Posts: 5
Stimmt das SessionHandling hatte ich kurz(testweise) gelöscht und vergessen wieder rein zu kopieren.
Bekommen jetzt aber die Fehlermeldung:
"Update queries only supported through HQL;"
Scheinbar ist dies das Problem.

Was ich aber jetzt nicht verstehe:
Wie kann ich einen Eintrag in einer Tabelle löschen, wenn die Primary key über mehrere Felder verteilt ist, und daher die *Id Klasse ertstellt wird.

Danke!
Markus


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 2:22 am 
Newbie

Joined: Tue May 31, 2005 10:31 am
Posts: 5
Ich sollte vielleicht noch ausführlicher erklären was ich eigentlich machen will.
Ich habe eine Tabelle User und eine Tabelle UserToGroup in der die Benutzer verschiedenen Gruppen zugeordnet sind. Jetzt möchte ich einen Bestimmten Benutzer löschen, wie kann ich dass machen? UserToGroup hat einen zusammen gestezten PK aus user_id und group_id.

Danke!


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.