-->
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: Ergebnis von ManyToMany-Beziehung abhängig vom PrimaryKey
PostPosted: Fri May 27, 2011 7:38 am 
Newbie

Joined: Fri May 27, 2011 7:17 am
Posts: 4
Hallo zusammen,

ich habe folgendes Problem:

Ich habe eine ManyToMany Beziehung von Umgebung zu Mandanten und umgekehrt. In den jeweiligen Klassen habe ich dann ein Set definiert mit der Beziehung. Wenn ich nun die Mandanten zu einer Umgebung auslesen will bekomme ich dort kein Ergebnis, will ich allerdings die Umgebungen in denen ein Mandant ist auslesen, dann kriege ich das richtige Ergebnis.

Weitere Tests haben eine kleine Matrix ergeben, wann auslesen nicht möglich ist:

Parenttype / Childtype / Result
Integer / String / ok
String / String / nicht ok
String / Integer / nicht ok
Integer / Integer / ok

Ich habe dann einen JCC-Trace aufgesetzt, welcher zeigt, dass das richtige SQL geschickt wird und auch ein Ergebnis liefert. Es kommt allerdings nichts im Set der Umgebungs-Klasse an.

Hat hier jemand eine Idee, wo der Fehler liegt oder ob es ein grundsätzliches Problem mit ManyToMany und String-PrimaryKeys gibt?

Mit freundlichen Grüßen

Maddin
Klasse Umgebung
Code:
package de.test;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "UMGEBUNG")
public class UMGEBUNG implements Serializable {

   private static final long serialVersionUID = -1410843033017704531L;

   @Id
   private String nameStage;

   @ManyToMany (fetch=FetchType.LAZY, cascade=CascadeType.ALL)
   @JoinTable(name = "MANDANT_X_STAGE", joinColumns = { @JoinColumn(name = "NAMESTAGE", referencedColumnName = "NAMESTAGE") }, inverseJoinColumns = { @JoinColumn(name = "NRMANDANT", referencedColumnName = "NRMANDANT") })   
   private Set<Mandant> mandanten;   
   public String getNameStage() {
      return nameStage;
   }
   public void setNameStage(String nameStage) {
      this.nameStage = nameStage;
   }
   public Set<Mandant> getMandanten() {
      return mandanten;
   }
   public void setMandanten(Set<Mandant> mandanten) {
      this.mandanten = mandanten;
   }
}


Klasse Mandant
Code:
package de.test;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table (name="MANDANT")
public class Mandant implements Serializable {

   @Id
   private Integer nrMandant;
      
   private String ip;

   @ManyToMany (mappedBy="mandanten")
   private Set<Umgebung> stages;

   public Integer getNrMandant() {
      return nrMandant;
   }

   public void setNrMandant(Integer nrMandant) {
      this.nrMandant = nrMandant;
   }

   
   public Set<Umgebung> getStages() {
      return stages;
   }

   public void setStages(Set<Umgebung> stages) {
      this.stages = stages;
   }
   
}

persistence.xml
Code:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
   <persistence-unit name="zkrsrv" transaction-type="RESOURCE_LOCAL">
      <class>de.gad.wap.zkr.data.jpa.base.Umgebung</class>
      <class>de.gad.wap.zkr.data.jpa.base.Mandant</class>
      <properties>
         <property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver"/>
         <property name="javax.persistence.jdbc.user" value="*"/>
         <property name="javax.persistence.jdbc.password" value="*"/>
         <property name="javax.persistence.jdbc.url" value="*"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
         <property name="hibernate.max_fetch_depth" value="3"/>
         <property name="hibernate.show_sql" value="true"/>
       
         <!-- cache configuration -->
         <!-- property name="hibernate.ejb.classcache.org.hibernate.ejb.test.Item" value="read-write"/-->
         <!-- property name="hibernate.ejb.collectioncache.org.hibernate.ejb.test.Item.distributors" value="read-write, RegionName"/-->

         <!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file -->
         <!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
      </properties>
   </persistence-unit>
</persistence>

Ausführung
Code:
      
EntityManagerFactory emf = Persistence.createEntityManagerFactory("zkrsrv");
      EntityManager em = emf.createEntityManager();
      EntityTransaction tx = em.getTransaction();
      tx.begin();
      Umgebungstage = em.find(Umgebung.class, new String("BAFUT"));
      Set<Mandant> mandanten = stage.getMandanten();
      System.out.println("Mandanten: " +mandanten.size());

      Mandant m = em.find(Mandant.class, new Integer(4918));
      Set<Umgebung> stages = m.getStages();
      System.out.println("Stages: " + stages.size());

---------------------------------------
360 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
391 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.4.Final
407 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
407 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
422 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
625 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.6.4.Final
2047 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: de.test.UMGEBUNG
2047 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity de.test.UMGEBUNG on table UMGEBUNG
2079 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: de.test.Mandant
2079 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity de.test.Mandant on table MANDANT
2141 [main] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
2219 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
2266 [main] WARN org.hibernate.mapping.RootClass - composite-id class does not override equals(): de.gad.wap.zkr.data.jpa.asw.Anwendungsversion
2266 [main] WARN org.hibernate.mapping.RootClass - composite-id class does not override hashCode(): de.gad.wap.zkr.data.jpa.asw.Anwendungsversion
2985 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.DB2Dialect
3016 [main] INFO org.hibernate.engine.jdbc.JdbcSupportLoader - Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
3016 [main] INFO org.hibernate.cfg.SettingsFactory - Database ->
       name : DB2/AIX64
    version : SQL09073
      major : 9
      minor : 7
3016 [main] INFO org.hibernate.cfg.SettingsFactory - Driver ->
       name : IBM DB2 JDBC Universal Driver Architecture
    version : 3.53.95
      major : 3
      minor : 53
3016 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
3032 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 3
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
3032 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
3032 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: enabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
3032 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
3047 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
3047 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
3063 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
3063 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
3063 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
3063 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
3063 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
3063 [main] INFO org.hibernate.cfg.SettingsFactory - Check Nullability in Core (should be disabled when Bean Validation is on): enabled
3094 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [characters_clob] overrides previous : org.hibernate.type.PrimitiveCharacterArrayClobType@76b876b8
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [clob] overrides previous : org.hibernate.type.ClobType@19761976
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Clob] overrides previous : org.hibernate.type.ClobType@19761976
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_materialized_blob] overrides previous : org.hibernate.type.WrappedMaterializedBlobType@ef30ef3
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [wrapper_characters_clob] overrides previous : org.hibernate.type.CharacterArrayClobType@6e686e68
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_clob] overrides previous : org.hibernate.type.MaterializedClobType@66e766e7
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [materialized_blob] overrides previous : org.hibernate.type.MaterializedBlobType@729d729d
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [blob] overrides previous : org.hibernate.type.BlobType@441a441a
3125 [main] INFO org.hibernate.type.BasicTypeRegistry - Type registration [java.sql.Blob] overrides previous : org.hibernate.type.BlobType@441a441a
4079 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
Hibernate: select applicatio0_.nameStage as nameStage2_0_, applicatio0_.SSODOMAENE as SSODOMAENE2_0_ from UMGEBUNG applicatio0_ where applicatio0_.nameStage=?
Hibernate: select mandanten0_.NAMESTAGE as NAMESTAGE2_1_, mandanten0_.NRMANDANT as NRMANDANT1_, mandant1_.nrMandant as nrMandant3_0_, mandant1_.ip as ip3_0_ from MANDANT_X_STAGE mandanten0_ inner join MANDANT mandant1_ on mandanten0_.NRMANDANT=mandant1_.nrMandant where mandanten0_.NAMESTAGE=?
Mandanten: 0
Hibernate: select stages0_.NRMANDANT as NRMANDANT3_1_, stages0_.NAMESTAGE as NAMESTAGE1_, applicatio1_.nameStage as nameStage2_0_, applicatio1_.SSODOMAENE as SSODOMAENE2_0_ from MANDANT_X_STAGE stages0_ inner join UMGEBUNG applicatio1_ on stages0_.NAMESTAGE=applicatio1_.nameStage where stages0_.NRMANDANT=?
Stages: 1



Top
 Profile  
 
 Post subject: Re: Ergebnis von ManyToMany-Beziehung abhängig vom PrimaryKey
PostPosted: Mon May 30, 2011 2:15 am 
Newbie

Joined: Fri May 27, 2011 7:17 am
Posts: 4
Also das Problem besteht nur mit DB2.

Unter mySQL und H2 tritt das Problem nicht auf.


Top
 Profile  
 
 Post subject: Re: Ergebnis von ManyToMany-Beziehung abhängig vom PrimaryKey
PostPosted: Mon May 30, 2011 5:55 am 
Newbie

Joined: Fri May 27, 2011 7:17 am
Posts: 4
Problem wurde gefunden und liegt im Datentyp.

Wird die PrimaryKey Spalte als VARCHAR angelegt, dann geht es.

Ist da irgendetwas bekanntes? Oder wo meldet man sowas bei Hibernate?


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.