-->
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.  [ 9 posts ] 
Author Message
 Post subject: inner class in database?
PostPosted: Fri Aug 20, 2004 9:00 pm 
Beginner
Beginner

Joined: Mon Jul 19, 2004 4:55 am
Posts: 34
Hibernate version:2.1.4

Mapping documents:no document for the moment

Code between sessionFactory.openSession() and session.close():not yet

Full stack trace of any exception that occurs:no trace

Name and version of the database you are using:Oracle 9i

Debug level Hibernate log excerpt:?

hello,
I just want to know how hibernate proceed with inner class.
I have Class1 and Class2. a Class1 object have only one Class2 object.
I want to have only one table in my database which has every attributes (from both classes).
I think that there is something like Class1$Class2 but i don"t know where i have to put this line...
what is the configuration of the mapping files? and is it possible to have only one table in database?
thanx a lot


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 8:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can't map non-static inner classes.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 8:44 am 
Beginner
Beginner

Joined: Mon Jul 19, 2004 4:55 am
Posts: 34
so Class1 and Class 2 have to be static?
can you give me an example for mapping files please?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
To map a static inner class just use Class1$Class2 as classname in your mappings.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 22, 2004 8:25 am 
Beginner
Beginner

Joined: Mon Jul 19, 2004 4:55 am
Posts: 34
ok but, where have i to put it? in the mapping file of Class1 or in the mapping file of class2? what is the tag?
and what is the result in database? one table, or 2 tables?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 22, 2004 9:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can map a static inner class just like any other class.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 6:31 am 
Beginner
Beginner

Joined: Mon Jul 19, 2004 4:55 am
Posts: 34
my class :
Code:
ublic class Record {
   
   private Long id;
   private int quantity;

   private Toto toto;
   
   public Record() {}
   
   public Record(
         Long id,
         int quantity,
   ) {
      this.id = id;
      this.quantity = quantity;
   }

   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public int getQuantity() {
      return quantity;
   }

   public void setQuantity(int quantity) {
      this.quantity = quantity;
   }


   public class Toto {

      protected int id;
      protected Record record;
      protected String champ1;
      
      /**
       * @return Returns the champ1.
       */
      public String getChamp1() {
         return champ1;
      }
      /**
       * @param champ1 The champ1 to set.
       */
      public void setChamp1(String champ1) {
         this.champ1 = champ1;
      }
      /**
       * @return Returns the id.
       */
      public int getId() {
         return id;
      }
      /**
       * @param id The id to set.
       */
      public void setId(int id) {
         this.id = id;
      }
      /**
       *
       */
      public Toto() {
         super();

      }


      /**
       * @return Returns the record.
       */
      public Record getRecord() {
         return record;
      }
      /**
       * @param record The record to set.
       */
      public void setRecord(Record record) {
         this.record = record;
      }
   }

   /**
    * @return Returns the toto.
    */
   public Toto getToto() {
      return toto;
   }
   /**
    * @param toto The toto to set.
    */
   public void setToto(Toto toto) {
      this.toto = toto;
   }
}


mapping file :
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<!-- Component org.hibernate.perf.Record$Toto is a nested class! -->
<hibernate-mapping>
   <!-- org.hibernate.perf.Record root -->
   <class name="org.hibernate.perf.Record" table="Record">
      <id name="id" type="long" column="id">
         <generator class="native"/>
      </id>
      <property name="quantity" column="quantity" type="int"/>
      <property name="toto" column="toto" type="org.hibernate.perf.Record$Toto"/>
   </class>
</hibernate-mapping>


exception :
[code]
23 ao


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 8:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is not a static inner class. Or do you see any "static" keyword there?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 12:32 pm 
Beginner
Beginner

Joined: Mon Jul 19, 2004 4:55 am
Posts: 34
I tried with a static class but i had the same error....
another idea?


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