-->
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.  [ 5 posts ] 
Author Message
 Post subject: No discriminator found for.. PLEASE HELP!!
PostPosted: Thu Mar 15, 2007 8:49 am 
Newbie

Joined: Tue Feb 20, 2007 6:54 am
Posts: 7
Hi Guys,

Any help here would be great.

I have got two classes ChildXMLClassElement and RootElement whic extend XMLClassElement and I decided to use the table per class hierarchy. My mapping file is as such.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="schemas">
<class name="XMLClassElement" table="XML_CLASS_ELEMENT">
<id name="id" column="XML_CLASS_ELEMENT_ID">
<generator class="increment"/>
</id>
<property name="sourceClassName"/>
<property name="displayOrder"/>
<property name="xmlElementName"/>
<property name="filterConditions"/>
<property name="resultLimit"/>
<property name="sortByProperty"/>
<property name="sortOrder"/>
<property name="sortType"/>
<set name="xmlPropertyElements" inverse="true">
<key column="XML_CLASS_ELEMENT_ID"/>
<one-to-many class="XMLPropertyElement"/>
</set>
<subclass name="ChildXMLClassElement" discriminator-value="CH">
<many-to-one name="parent" column="XML_CLASS_ELEMENT_ID" not-null="true"/>
<many-to-one name="rootElement" column="XML_CLASS_ELEMENT_ID" not-null="true"/>
<set name="childXMLClassElements" inverse="true">
<key column="XML_CLASS_ELEMENT_ID"/>
<one-to-many class="ChildXMLClassElement"/>
</set>
</subclass>
<subclass name="RootElement" discriminator-value="RE">
<many-to-one name="parent" column="SCHEMA_DEFINITION_ID" not-null="true"/>
<set name="childXMLClassElements" inverse="true">
<key column="XML_CLASS_ELEMENT_ID"/>
<one-to-many class="ChildXMLClassElement"/>
</set>
<set name="queries" inverse="true">
<key column="XML_CLASS_ELEMENT_ID"/>
<one-to-many class="Query"/>
</set>
</subclass>
</class>
</hibernate-mapping>

But when I try to run the application I get the following error.

Initial SessionFactory creation failed.org.hibernate.MappingException: No discriminator found for schemas.RootElement. Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses
16:22:40,984 ERROR [EventManagerServlet]:253 - Servlet.service() for servlet EventManagerServlet threw exception
java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at events.EventManagerServlet.doGet(EventManagerServlet.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.MappingException: No discriminator found for schemas.RootElement. Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses
at org.hibernate.mapping.SingleTableSubclass.validate(SingleTableSubclass.java:41)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 17 more

I cannot understand what I am doing wrong here. I have gone through the hibernate documentation but I couldnt find any help there.
Please please please HELP!

Thanks,
pix.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 9:21 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
You specified the discriminator value on your subclasses, but forgot to tell the base class what column to use to act as the discriminator. e.g. <discriminator column="xmlElementName" type="string"/> instead of your xmlElementName column definition (assuming xmlElementName is the discriminator, couldn't tell from casual observation).

See http://www.hibernate.org/hib_docs/v3/re ... criminator


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 9:49 am 
Newbie

Joined: Tue Feb 20, 2007 6:54 am
Posts: 7
I read that in the hibernate tutorial, but i dont understand the concept of what a discriminator should be. I dont know which column i should use and why. Can u please give me a small example.

thanks,
pix.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:17 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
The discriminator column is the one that determines which subclass is appropriate for the entity. e.g.

Code:
Table Party(number primaryKey, varchar partyType, number foreignKey)
Table Person(number personKey, varchar personName)
Table Company(number companyKey, varchar companyName)

So, the Party table's foreign key can either refer to the primary key of the Person table or the primary key of the Company table, depending on (i.e. discriminated by) the value of the partyType string. If partyType='PERSON', then the foreignKey field maps a one-to-one relationship to the Person table. Likewise, if the partyType='COMPANY', then the foreignKey field maps a one-to-one relationship to the Company Table. Mappings would look like this:

<hibernate-mapping>
  <class name="eg.Party" table="Party">
    <id name="id" column="primaryKey"/>
    <discriminator column="partyType" type="string"/>
    <subclass name="eg.PartyForPerson" discriminator-value="PERSON">
      <many-to-one name="person" class="eg.Person">
        <column name="foreignKey"/>
      </many-to-one>
    </subclass>
    <subclass name="eg.PartyForCompany" discriminator-value="COMPANY">
      <many-to-one name="company" class="eg.Company">
        <column name="foreignKey"/>
      </many-to-one>
    </subclass>
  </class>
</hibernate-mapping>

Not shown: mappings for Person,Company


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:21 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
The discriminator column is an hibernate internal column.
It tells hibernate what's the class of a row when fetching an object from the database. With this row hibernate will be able to instantiate the right subclass. Don't care for the name of the column just call it discriminator or something like that and everything will be fine.

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.