-->
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: Mapping interfaces and non-polymorphic queries
PostPosted: Thu Feb 02, 2006 11:05 pm 
Newbie

Joined: Thu Feb 02, 2006 10:55 pm
Posts: 3
Hi,

It's been here a million times but always in a different flavour. I've got UserType interface implemented by UserTypeVO. Naturally I would like to map the interface rather than implementation.

I've mapped it kinda successful, but Hibernate forces me to supply a class disciminator, which I have not (there is no inheritance). Is there any way to overcome this?

All I want is the UserTypeVO to be returned in the queries that go on UserType

If don' specify the discriminator I get:

Quote:
org.hibernate.MappingException: No discriminator found for com.eblib.components.business.cemanager.impl.dao.UserTypeVO. Discriminator is needed when 'single-table-per-hiearchy' is used and a class has subclasses


Here's my mapping:

Code:
<hibernate-mapping>
   <class name="com.eblib.components.business.cemanager.UserType" table="EBL_USER_TYPE" lazy="false" select-before-update="true">

      <meta attribute="interface">true</meta>

      <id name="id" column="USER_TYPE_ID" type="java.lang.Long" unsaved-value="null">
         <generator class="hilo">
            <param name="table">EBL_HIBERNATE_KEY</param>
            <param name="column">NEXT_VALUE</param>
         </generator>
      </id>

      <property name="acronym" type="java.lang.String" update="true" insert="true" column="ACRONYM" />

      <property name="active" update="true" type="yes_no" insert="true" column="ACTIVE" />

      <property name="guest" update="true" type="yes_no" insert="true" column="IS_GUEST" />

      <property name="patronType" update="true" type="yes_no" insert="true" column="IS_PATRON_TYPE" />

      <property name="name" type="java.lang.String" update="true" insert="true" column="NAME" />

      <property name="system" type="java.lang.String" update="true" insert="true" column="SYSTEM" />

      <subclass name="com.eblib.components.business.cemanager.impl.dao.UserTypeVO">
         <meta attribute="implements">com.eblib.components.business.cemanager.UserType</meta>
      </subclass>

   </class>

</hibernate-mapping>


Many thanks

Maciej Mastalarczuk


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 1:15 pm 
Newbie

Joined: Mon Feb 20, 2006 1:10 pm
Posts: 1
I ran into the same problem.

My solution was not using the subclass stuff but just create a mapping as if you were mapping the VO directly, but add the entity-name="<your VO interface>"

This seems to work except that when you go to save or saveOrUpdate you need to explicitly pass the interface name with your object:

session.saveOrUpdate(VOInterface.class.getName(), object);


Not sure if this is the correct way of doing it, but it does seem to work.

Mapping an interface instead of a concrete implementation seems less obvious that I had thought it would be.

-Cameron


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 12:31 pm 
How do you use this to do a hibernateTemplate().load()?

I have this:

return (CardHolder) getHibernateTemplate().load(CardHolder.class, id);

where CardHolder is the interface and I mapped it so:

<class name="com.blah.cortex.domain.defaultimpl.DefCardHolder"
entity-name="com.blah.cortex.domain.CardHolder"
table="CRDDET">

and the cast throws a ClassCastException.


Top
  
 
 Post subject:
PostPosted: Fri Jun 02, 2006 12:45 pm 
Sorry, ignore me, momentary lapse of concentration.

This does work nicely.

I'd like to know why Cameron is so hesitant about the method though.


Top
  
 
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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.