-->
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: Inheritance, HQL and searching by overriden properties
PostPosted: Mon Aug 29, 2011 11:01 am 
Newbie

Joined: Mon Aug 29, 2011 10:31 am
Posts: 1
Hi,

I have following problem, there are several

Code:
@MappedSuperclass
abstract class Base<TID, T> {
  TID id;
  T data;

  @Transient
  abstract getId();

  @Transient
  abstract getData;
}

@Entity()
@Table(...)
@Inheritance(strategy = SIMPLE_TABLE)
@SequenceGenerator(...)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
abstract class Value<T> extends Base<Long, T> {
 
  @Id()
  @GeneratedValue(...)
  ....

   public interface Type{
     int VARCHAR = 1;
     int NUMERIC = 2;
   }

   String propertyName;

   @ManyToOne
   @JoinColumn(name = "componentId")
   public Component getComponent() {
     return component;
   }

  @Entity()
  @DiscriminatorValue(Type.VARCHAR)
  public static class Varchar extends Value<String> {
       @Override
       @Column(name="dataString")
       String getData() {
           return data;
       }
  }

  @Entity()
  @DiscriminatorValue(Type.NUMERIC)
  public static class Numeric extends FValue<Long> {
    
   @Override
   @Column(name="dataLong")
   public Long getData() {
      return data;
   }
   }

}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
class Component{
  protected Long id;
  private Map<String, FValue<?>> values = new HashMap<String, FValue<?>>();

@OneToMany(mappedBy = "component")
@MapKeyColumn(name = "propertyName")
public Map<String, FValue<?>> getValues() {
   return values;
}
}


Others entities like Element extends Component.

I'd like do something like this
Code:
select comp, v from Component comp inner join comp.values v where v.propertyName = 'exampleName' and v.data = 'example';


Of course i know that, hibernate doesn't know type of values, but I can imagine casting or translate this to sql like this (value.type = 1 and value.dataString = 'example') or (value.type = 2 and value.dataLong = 'example') in where clause.

We can do this that
Code:
select comp, fv from Component as comp inner join comp.values as fv where comp.values['dpLongDesc'] in (select a.id from FValue$Numeric where a.data = :str)


but it multiplies amout of select that is not optimal.


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.