-->
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: polymorphic native query
PostPosted: Sat Feb 03, 2007 6:49 pm 
Newbie

Joined: Wed Jan 24, 2007 6:17 pm
Posts: 3
Hi,

Hibernate version: 3.2

Is there any chance to make a polymorphic native query? I want to query a table that holds a class hierarchy (table-per hierarchy-mapping) with native SQL. If I specify the class with addEntity as the superclass of my hierarchy, hibernate just extracts only the attributes of the superclass.

Is there any way to do that? I want to make use of fulltext-search features of the mysql database.

Cheers, Hape


Top
 Profile  
 
 Post subject: Polymorphic collection of the superclass
PostPosted: Fri Jul 20, 2007 9:34 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
Hi,

I am looking for a solution to this problem as well.

I have read here [http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/04/02#three] that it is not possible.

Is this still the case. Is there a way around this using unions or subclass joins.

thanks,
Richie.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 1:46 pm 
Regular
Regular

Joined: Fri Dec 17, 2004 10:38 am
Posts: 54
Pardon me, but

Code:
<hibernate-mapping package="org.foo">
   <class name="SuperType" table="SUPER_HIERARCHY" discriminator-value="super">
      <id name="id" column="ID" type="long" unsaved-value="0">
         <generator class="native" />
      </id>
      <discriminator column="PAYMENT_TYPE" type="string" />

      <subclass name="ChildType" discriminator-value="child" />
   </class>
   <sql-query name="getAll">
      <return alias="x" class="SuperType"></return>
      select {x.*} from SUPER_HIERARCHY x
   </sql-query>


</hibernate-mapping>


Code:
SuperType s = new SuperType();
      ChildType c = new ChildType();
      session.save(s);
      session.save(c);

      List<SuperType> result = session.getNamedQuery("getAll").list();
      System.out.println(result);


and output
Code:
Hibernate: insert into SUPER_HIERARCHY (ID, PAYMENT_TYPE) values (null, 'super')
Hibernate: insert into SUPER_HIERARCHY (ID, PAYMENT_TYPE) values (null, 'child')
Hibernate: select x.ID as ID0_0_, x.PAYMENT_TYPE as PAYMENT2_0_0_ from SUPER_HIERARCHY x
[org.foo.SuperType@1dacccc, org.foo.ChildType@d58939]


hibernate version is 3.2.4.sp1, db - h2


Top
 Profile  
 
 Post subject: polymorphic query
PostPosted: Wed Jul 25, 2007 11:24 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
Hi,

It seems then that there is a way around this using subclass join instead of a joined-subclass. I dont have a descriminator column though but I can generate this using a forumla.

thanks,
Richie.


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.