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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate3 and nested classes (or extending hibernate?)
PostPosted: Mon Apr 18, 2005 7:47 pm 
Newbie

Joined: Mon Apr 18, 2005 6:32 pm
Posts: 5
Hi,
I am using hibernate3 and think its quite a nice piece of software. Unfornutately I am having the job to extend hibernate for use with objectteams Java (http://www.objectteams.org) and the codebase of hibernate is somewhat overwhelming to me.
As a short explanation, Objectteams is an extension to java that introduces teamclasses and roleclasses. An example of Objectteams looks like this:

Code:
public team class myTeam {
     synthetic WeakHashMap _OT$cache$MyRole <MyBase, MyRole>
     ...
     public class MyRole playedBy MyBase {
     synthetic final MyBase _OT$base
     ...
     }
}


As you can see Teamclasses are the outer classes that contain roleclasses as nested classes. In this case playedBy means a relation to some kind of baseclass. These classes are related to each other with references (the synthetic values), that are generated by a compiler. Such a thing shoud be stored with hibernate including the generated values.

My question at the moment is, how can I store some kind of nested class in normal style java with hibernate. how can I store a thing like this:

Code:
public class myClass {
     ...
     public class myNestedClass {
     ...
     }
}


Probably this can be done in some way. If not, someone might have enough knowledge on how to extend hibernate to do this, e.g. with
custom types (I am not that far with knowledge about hibernate extension programming :-( ). If you have more suggestion how a thing like this can be realized with hibernate, feel free.

Regards,
Micha K.


Last edited by mso on Thu Dec 01, 2011 12:50 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 5:26 am 
Newbie

Joined: Mon Apr 18, 2005 6:32 pm
Posts: 5
Difficult here are to address the inner classes. Quite a lot trial and error has brought up the first step of my problem. I am not really sure, if this is successful at all, but at least there are no hibernate errors ;-).
Use a second mapping file with the name myClass$nestedClass.hbm.xml
and use myClass.nestedClass.class in the configuration creation. The mapping xml is then:

Code:
<?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="mytest" default-cascade="save-update">
   <class name="MyClass$nestedClass">
                             
      <id name="id" type="long">
         <generator class="native"/>
      </id>
      <property name="text" type="string"/>
   </class>
</hibernate-mapping>


If you have more information, if or if not this can work et. al. then let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 5:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - but his classes are NON static so kinda hard for hibernate to instantiate them ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 2:09 pm 
Newbie

Joined: Mon Apr 18, 2005 6:32 pm
Posts: 5
I dont understand what you mean. Can you give me a more detailed answer?
Actually I dont know much about implicit/explicit semantics of inner classes.
I going to have a look in the sun docs.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 2:27 pm 
Newbie

Joined: Mon Apr 18, 2005 6:32 pm
Posts: 5
A short snipplet from http://java.sun.com/docs/books/tutorial/java/javaOO/summarynested.html

A class defined within another class is called a nested class. Like other members of a class, a nested class can be declared static or not. A nonstatic nested class is called an inner class. An instance of an inner class can exist only within an instance of its enclosing class and has access to its enclosing class's members even if they are declared private.

It remains difficult on how to solve my problem.
But thanks for pointing out.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 2:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you might be able to do some of this via UserTypes - but it requires some access to the outer class from which you can create the inner non-static class...but it can probably only be a property/value and not a entity in its own right (since its not ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 3:49 pm 
Newbie

Joined: Mon Apr 18, 2005 6:32 pm
Posts: 5
Somekind of constructor access from outside seems to exist in
my original team/role classes szenario (this seems to be generated
by the objectteams compiler). I'm not sure on how to use it, so I have to discuss this with my supervisor first, before I can make further statements.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 3:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
but its surely not something that is easily persisted...(as in its not supported by hibernate because is very seldom usefull together with the fact you cannot construct the dependent object without the outer object)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Yeah eh? Canadian eh?
PostPosted: Thu Sep 18, 2008 1:51 pm 
Newbie

Joined: Thu Sep 18, 2008 1:47 pm
Posts: 1
Hibernate could allow the implementor to specify their own class factory to solve problems like these. Although that takes some control away from Hibernate that would otherwise enable Hibernate to manage the object layer in a most efficient and optimal manner.

Was that wordy enough?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 9:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes, and it is called UserTypes

_________________
Max
Don't forget to rate


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