-->
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.  [ 1 post ] 
Author Message
 Post subject: incorrect generated SQL from EJBQL
PostPosted: Fri Nov 21, 2008 11:58 am 
Newbie

Joined: Fri Nov 21, 2008 10:38 am
Posts: 3
Location: Germany
Hello,

i'm using JBoss AS 4.2.3.GA.

I have an Entity Schmelze with two One-To-One bidirectional relationships SollSchmelze and VerlustSchmelze which have an embedded Attribut PlanungsNummer:

Code:
@Entity
public class Schmelze implements Serializable {
   ...
   private SollSchmelze sollSchmelze;
   private VerlustSchmelze verlustSchmelze;
   ...
   @OneToOne(mappedBy="schmelze", optional = true)
   public SollSchmelze getSollSchmelze() {
   return sollSchmelze;
   }

   @OneToOne(mappedBy="schmelze", optional = true)
   public VerlustSchmelze getVerlustSchmelze() {
   return verlustSchmelze;
   }
   ...
}

@Entity
public class SollSchmelze implements Serializable {
   ...
   private Schmelze schmelze;
   private PlanungsNummer planungsNummer;
   ...
   @Embedded
   public PlanungsNummer getPlanungsNummer() {
   return planungsNummer;
   }

   @OneToOne(optional = true)
   @JoinColumn(name = "schmelze_id")
   public Schmelze getSchmelze() {
   return schmelze;
   }
   ...
}

@Entity
public class VerlustSchmelze implements Serializable {
   ...
   ...
   private Schmelze schmelze;
   private PlanungsNummer planungsNummer;
   ...
   @Embedded
   public PlanungsNummer getPlanungsNummer() {
   return planungsNummer;
   }

   @OneToOne(optional = true)
   @JoinColumn(name = "schmelze_id")
   public Schmelze getSchmelze() {
   return schmelze;
   }
   ...
}

@Embeddable
public class PlanungsNummer implements Serializable {
   ...
   private int nummer;
   ...
}




I want to select an Schmelze-entity with a relation to an SollSchmelze-entity with a specific PlanungsNummer. OR with a relation to an VerlustSchmelze-entity with a specific PlanungsNummer.

For this, i created the following EJB-QL statement:

Code:
  SELECT
      OBJECT(s)
  FROM
      Schmelze AS s
  WHERE
      (
          (
              s.sollSchmelze IS NOT NULL
              AND s.sollSchmelze.planungsNummer.nummer = :planungsnummer1
          )
          OR (
              s.verlustSchmelze IS NOT NULL
              AND s.verlustSchmelze.planungsNummer.nummer = :planungsnummer2
          )
      ) 
  ORDER BY
      s.entstehung DESC



Hibernate generate this SQL statement:

Code:
       
   select
      schmelze0_.id as id41_,
      schmelze0_.nummer as nummer41_,
      schmelze0_.kennungGiessAnlage as kennungG3_41_,
      schmelze0_.entstehung as entstehung41_,
      schmelze0_.pfanne_id as pfanne6_41_,
      schmelze0_.spaeteErzZugabe as spaeteEr5_41_
  from
      Schmelze schmelze0_,
      SollSchmelze sollschmel1_,
      VerlustSchmelze verlustsch2_
  where
      schmelze0_.id=sollschmel1_.schmelze_id
      AND schmelze0_.id=verlustsch2_.schmelze_id
      and (
          (
              schmelze0_.id is not null
          )
          and sollschmel1_.nummer=?
          or (
              schmelze0_.id is not null
          )
          and verlustsch2_.nummer=?
      )
  order by
      schmelze0_.entstehung DESC limit ?



This would always result in an empty resultlist, because the Schmelze never is a SollSchmelze and a VerlustSchmelze.

I'd expected something like:

Code:

   ...
  where
      schmelze0_.id=sollschmel1_.schmelze_id
      OR schmelze0_.id=verlustsch2_.schmelze_id
      and (



How i have to change the EJB-QL statement to achieve the correct ResultList?

Thx

Ludger


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

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.