-->
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: Help with discrimators and subclasses?
PostPosted: Fri Jul 23, 2010 11:30 pm 
Newbie

Joined: Sun Jun 06, 2010 11:00 pm
Posts: 5
Hey, I'm pretty new to hibernate and just been playing around with it, I've had this working by just using
the concrete StudentDetails class but then I tried to get it to work by creating an Interface class have having
my concrete StudentDetails implement the StudentInterface class. I can't seem to get it to work now, I think it has something to do with the way I'm using descriminator, subclass and a many-to-one or one-to-one relationship I'm missing, sorry not sure abt this stuff. I manually created a new column in the "student" table called tableDescriminator, but this is not a property of any of my classes. I thought hibernate will use the classname.


Student table
ID
student_name
student_address
email
tableDescriminator

contact.hbm.xml
Code:

<class name="Tute2G.Tute2A.StudentInterface" table="student">
     <id name="id" type="int" column="id" >
        <generator class="increment"/>
     </id>
   
   <discriminator>
        <column name="tableDescriminator"/>
    </discriminator> 

     <property name="studentName">
         <column name="student_name" />
     </property>
   
    <property name="studentAddress">
         <column name="student_address" />
     </property>
   
    <property name="email">
         <column name="email" />
     </property>
       
   <subclass name="Tute2G.Tute2A.StudentInterface"/>



My Student Interface Class
Code:

package Tute2G.Tute2A;

public interface StudentInterface {


   public String getStudentName();

   public void setStudentName(String studentName);

   public String getStudentAddress();

   public void setStudentAddress(String studentAddress);
   public String getEmail();

   public void setEmail(String email);

   public int getId();


   public void setId(int id);
}


My concrete Student class
Code:

package Tute2G.Tute2A;

public class Studentdetail implements StudentInterface{
     private String studentName;
     private String studentAddress;
     private String email;
     private int id;
    
     public String getStudentName(){
       return studentName;
     }
    
     public void setStudentName(String studentName){
       this.studentName = studentName;
     }
    
     public String getStudentAddress(){
       return studentAddress;
      
     }
    
     public void setStudentAddress(String studentAddress){
       this.studentAddress = studentAddress;
     }
    
     public String getEmail(){
       return email;
     }
    
     public void setEmail(String email){
       this.email = email;
     }
    
     public int getId(){
       return id;
     }
    
     public void setId(int id){
       this.id = id;
     }
   }



Error Log

Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource contact.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:575)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1593)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1561)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1540)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1514)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1434)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1420)
at Tute2G.Tute2A.StudentCriteriaQueryTest.main(StudentCriteriaQueryTest.java:18)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping Tute2G.Tute2A.StudentInterface
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:145)
at org.hibernate.cfg.Configuration.add(Configuration.java:675)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:510)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:572)


Thanks heaps


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