-->
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: Abfrage mit HQL bei einer Vererbung
PostPosted: Thu Feb 08, 2007 5:54 pm 
Newbie

Joined: Sat Nov 25, 2006 7:29 pm
Posts: 2
Hallo,

ich muss leider eine Frage posten, aber ich komme echt nicht weiter.

Hibernate Version 3.2.0, October 16, 2006
und
Hibernate Annotations Version: 3.2.0.GA, 16.10.2006

Ich habe eine Vererbung mit Hibernate realisiert. Dazu nutze ich die InheritanceType.JOINED Strategie.

Wenn ich aber dann die abgeleitete Klasse mit Hilfe eines inner Join wieder aus der Datenbank lesen will, kommt es zu einem Fehler.

Mein Abfrage in HQL sieht wie folgt aus ...
Benutzer ist hierbei die Basisklasse und Suchender die Abgeleitete.

String abfrage = "select s from Suchender s inner join Benutzer b on s.id = b.id where (b.email = ? and b.passwort = ?)";

Dabei erhalte ich aber folgende Exception:

unexpected token: on near line 1, column 52 [select s from FK.Suchender s inner join Benutzer b on s.id = b.id where (b.email = ? and b.passwort = ?)]

Ich hoffe jemand kann mir helfen.

Gruß
Fireball

Code:
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
         
            <!-- Datenbank Connection Einstellungen für MySQL-->
            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="connection.url">jdbc:mysql://192.168.0.4/Anwendung</property>
            <property name="connection.username">xxxxx</property>
            <property name="connection.password">xxxxxx</property>
           
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
                       
            <!-- Zusätzliche Einstellungen-->
            <property name="hibernate.show_sql">true</property>
            <property name="hibernate.format_sql">true</property>
                         <!--<property name="hibernate.hbm2ddl.auto">create</property>-->
           
            <!-- Auflistung aller Klassen die gemappt werden sollen-->
              <mapping class="FK.Suchender"/>
              <mapping class="FK.Anbieter"/>
              <mapping class="FK.Vermittler"/>
              <mapping class="FK.Fehler"/>
   </session-factory>
</hibernate-configuration>


Code:

...
@Entity
public class Suchender
  extends Benutzer
{
  private Calendar verfügbar = null;

  public void setVerfügbar(Calendar verfügbar)
  {
    this.verfügbar = verfügbar;
  }

  @Column (name = "verfügbar")
  public Calendar getVerfügbar()
  {
    return verfügbar;
  }

}



Code von Benutzer Klasse
Code:
...
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Benutzer
{
  private Integer id;
  protected Calendar geburtsdatum;
  protected String anrede;
  protected String email;
  protected String fax;
  protected String firma;
  protected String handy;
  protected String land;
  protected String name;
  protected String ort;
  protected String passwort;
  protected String plz;
  protected String sessionid;
  protected String telefon;
  protected String titel;
  protected String vorname;
   
  public void setGeburtsdatum(Calendar geburtsdatum)
  {
    this.geburtsdatum = geburtsdatum;
  }
 
  /**
   * Die Methode aktualisiert die Daten mit der Datenbank
   */
  public void DatenAktualisieren()
  {
    try
    {
      DBAdapter.getInstance().Aktualisieren(this);
    }
    catch (Throwable e)
    {
      FehlerHandler.getInstance().FehlerSpeichern(e.getMessage(),e.getLocalizedMessage(),"Benutzer, Datenaktualisieren", new Date());
    }
  }
 
 
  @Column (name = "datum")
  public Calendar getGeburtsdatum()
  {
    return geburtsdatum;
  }

  public void setAnrede(String anrede)
  {
    this.anrede = anrede;
  }

  @Column (name = "anrede")
  public String getAnrede()
  {
    return anrede;
  }

  public void setEmail(String email)
  {
    this.email = email;
  }

  @Column (name = "email", nullable = false)
  public String getEmail()
  {
    return email;
  }

  public void setFax(String fax)
  {
    this.fax = fax;
  }
 
  @Column (name = "fax")
  public String getFax()
  {
    return fax;
  }
 
  public void setFirma(String firma)
  {
    this.firma = firma;
  }

  @Column (name = "firma")
  public String getFirma()
  {
    return firma;
  }

  public void setHandy(String handy)
  {
    this.handy = handy;
  }

  @Column (name = "handy")
  public String getHandy()
  {
    return handy;
  }

  public void setLand(String land)
  {
    this.land = land;
  }

  @Column (name = "land")
  public String getLand()
  {
    return land;
  }

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

  @Column (name = "name", nullable = false)
  public String getName()
  {
    return name;
  }

  public void setOrt(String ort)
  {
    this.ort = ort;
  }

  @Column (name = "ort")
  public String getOrt()
  {
    return ort;
  }

  public void setPasswort(String passwort)
  {
    this.passwort = passwort;
  }

  @Column (name = "passwort", nullable = false)
  public String getPasswort()
  {
    return passwort;
  }

  public void setPlz(String plz)
  {
    this.plz = plz;
  }

  @Column (name = "plz")
  public String getPlz()
  {
    return plz;
  }

  public void setSessionid(String sessionid)
  {
    this.sessionid = sessionid;
  }

  @Transient
  public String getSessionid()
  {
    return sessionid;
  }

  public void setTelefon(String telefon)
  {
    this.telefon = telefon;
  }

  @Column (name = "telefon")
  public String getTelefon()
  {
    return telefon;
  }

  public void setTitel(String titel)
  {
    this.titel = titel;
  }

  @Column (name = "titel")
  public String getTitel()
  {
    return titel;
  }

  public void setVorname(String vorname)
  {
    this.vorname = vorname;
  }

  @Column (name = "vorname", nullable = false)
  public String getVorname()
  {
    return vorname;
  }

  public void setId(Integer id)
  {
    this.id = id;
  }

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Integer getId()
  {
    return id;
  }
}
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 6:56 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2004 8:14 am
Posts: 20
Location: Mainz, Germany
Hallo,

ich bin mir nicht ganz sicher aber ich glaube
Quote:
on s.id = b.id

muss einfach weggelassen werden, da Hibernate weiß wie die Tabellen gejoined werden.

Gruss,

Matthias


Top
 Profile  
 
 Post subject: danke schön
PostPosted: Tue Feb 20, 2007 7:04 pm 
Newbie

Joined: Sat Nov 25, 2006 7:29 pm
Posts: 2
Hallo,

habe das Problem anders umschifft. Werde den Vorschlag aber mal ausprobieren, denn es werden noch einige Abfragen im Projekt folgen.

Ich hatte eine Variable auf einen Namen mit 'öäü usw.' gemappt. Das fand die Datenbank gar nicht so toll. Deswegen gabs nen crash.

Gruß

FireballGFX


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.