-->
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.  [ 2 posts ] 
Author Message
 Post subject: Breaking up a large Hibernate class
PostPosted: Sat Dec 12, 2009 3:03 pm 
Newbie

Joined: Sat Dec 12, 2009 2:58 pm
Posts: 2
Dear all,

I have a Hibernate class which is essentially just a wrapper around loads of collections.

So the class is (massively simplified/pseudo) something like:

Code:
@Entity 
public class MyClass {

  @OneToMany 
  Map1

  @OneToMany 
  Map2

  @OneToMany   
  Map3

  AddToMap1(); 
  AddToMap2(); 
  AddToMap3(); 
  RemoveFromMap1(); 
  RemoveFromMap2(); 
  RemoveFromMap3(); 
  DoWhateverWithMap1(); 
  DoWhateverWithMap2(); 
  DoWhateverWithMap3(); 

}


etc. Each of those Maps then has a few methods associated with it (add/remove/interrogate/etc).

As you can imagine, by the time I added the 10th collection or so, the class is getting a tad ridiculous in size.

What I'd love to do is something along the lines of:


Code:
@Entity 
public class MyClass {

  ClassWrappingMap1;

  ClassWrappingMap2;

  ClassWrappingMap3;
}


With all the various methods wrapped up in those classes:

Code:
public class ClassWrappingMap1 {

  @OneToMany
  Map

  AddToMap(); 
  RemoveFromMap(); 
  DoWhateverWithMap(); 

}


I thought perhaps I could use @Embedded for this, but I don't seem to be able to get it to work (Hibernate simply doesn't even try to persist the Map inside the wrapperClass). The relevant section in the reference documentation for whether or not this is possible uses ambiguous language ("While not supported by the EJB3 specification, Hibernate Annotations allows you to use association annotations in an embeddable object (ie @*ToOne nor @*ToMany)."). I suppose that should either be "or", or "but not".

So, basically - is the above possible?

Many thanks,
Ned


Top
 Profile  
 
 Post subject: Re: Breaking up a large Hibernate class
PostPosted: Sun Jan 10, 2010 11:28 am 
Newbie

Joined: Sat Dec 12, 2009 2:58 pm
Posts: 2
In case anyone stumbles upon this in the future.

It is possible to break up the class with @Embedded. The Collection works fine.

The reason I was having difficulty in the first place was because I was pointing at the interface, not the implementation. Added a quick @Target annotation and all is good.


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